Re: Non-rectangular 3D plot
- From: "Bookie via MathKB.com" <u43093@uwe>
- Date: Wed, 23 Apr 2008 19:36:28 GMT
Hi Roger,
I'm trying the method you've shown,since it is the most familiar for me.
The tip on parameter representation helped! I've modified your code to work
with my case, please see below. I am wondering if I have applied my 'for
loop' properly to get x and y vectors and the z matrix. My results are not
what I am expecting, although much improved over before! Thanks again!
% Range variables
Xpts = a:1:b;
Ypts = min:1:max;
% Preallocation of matricies
m = numel(Xpts);
n = numel(Ypts);
Z = zeros(4,m,n); %3d matrix, a 4x1 vector calculated over changes in vectors:
x (size m) & y (size n)
x = zeros(m);
y = zeros(n);
[ix,iy] = meshgrid(1:m,1:n); % Use a p by q mesh of ix & iy values
% Loop to create z-matrix
for i = 1:m
x(i) = min(X4) + (ix(i)-1)*(max(X4)-min(X4))/(m-1); % a <= x <= b
for j = 1:n
y(i,j) = (iy(j)-1).*(M*x(i)+b)/(n-1); % 0 <= y <= m*x+b
Variable1(i,j) = x(i) + y(i,j);
Variable2(i,j) = x(i) - y(i,j);
[Z(:,i,j)] = FunctionMfile(Variable1(i,j),Variable2(i,j),x(i),y(i,j))
;
end
end
[x,y] % check matrix
z(i,j) = Z(1,i,j); % plot of one layer of 3d matrix only, since 'surf' only
accepts z as a 2d matrix
surf(x,y,abs(Z))
colormap hsv
colorbar
Regards,
Bookie
Roger Stafford wrote:
Hi,[quoted text clipped - 5 lines]
----------
Bookie
In the 'surf' and 'surfc' functions it isn't necessary that the x-y domain
covered be a rectangle. It is only necessary that there be a two-parameter
representation of the desired surface in which the parameters fill a
rectangular space. In your example, you could use parameters, ix and iy
where
[ix,iy] = meshgrid(1:p,1:q); % Use a p by q mesh of ix & iy values
x = a + (ix-1)*(b-a)/(p-1); % a <= x <= b
y = (iy-1).*(m*x+b)/(q-1); % 0 <= y <= m*x+b
z = (Whatever your function of x and y is)
surf(x,y,z)
There is an example of a sphere generated by 'surf' in the function reference
to matlab. Study it to see how the parameterization works. In particular note
that what you call the "shadow" is a circle in this case.
Roger Stafford
--
Message posted via MathKB.com
http://www.mathkb.com/Uwe/Forums.aspx/matlab/200804/1
.
- Follow-Ups:
- Re: Non-rectangular 3D plot
- From: Bookie via MathKB.com
- Re: Non-rectangular 3D plot
- References:
- Non-rectangular 3D plot
- From: Bookie
- Re: Non-rectangular 3D plot
- From: Roger Stafford
- Non-rectangular 3D plot
- Prev by Date: Re: Variable name in a loop
- Next by Date: Re: Partial Derivative.
- Previous by thread: Re: Non-rectangular 3D plot
- Next by thread: Re: Non-rectangular 3D plot
- Index(es):
Relevant Pages
|