home *** CD-ROM | disk | FTP | other *** search
- function h=meshz(x,y,z,c)
- %MESHZ 3-D mesh with reference plane.
- % MESHZ(...) is the same as MESH(...) except that a "curtain" or
- % reference plane is drawn beneath.
- %
- % This routine only works for surfaces defined on a rectangular
- % grid. The matrices X and Y define the axis limits only.
- %
- % See also MESH.
-
- % Clay M. Thompson 3-20-91
- % Copyright (c) 1984-93 by The MathWorks, Inc.
-
- error(nargchk(1,4,nargin));
-
- if nargin==1, % Generate x,y matrices for surface z.
- if min(size(x)) == 1 | isstr(x)
- error('Invalid input argument.')
- end
- z = x;
- [m,n] = size(z);
- [x,y] = meshgrid(0:n-1,0:m-1);
- c = z;
-
- elseif nargin==2,
- if isstr(x) | isstr(y)
- error('Invalid input argument.')
- end
- if min(size(x)) == 1 | min(size(y)) == 1
- error('Invalid input argument.')
- end
- z = x; c = y;
- [m,n] = size(z);
- [x,y] = meshgrid(0:n-1,0:m-1);
- if any(size(c) ~= size(z))
- error('Invalid input argument.')
- end
-
- elseif nargin>=3,
- if isstr(x) | isstr(y) | isstr(z)
- error('Invalid input argument.')
- end
- [m,n] = size(z);
- [mx,nx] = size(x);
- [my,ny] = size(y);
- if m == 1 | n == 1
- error('Invalid input argument.')
- end
- [xx,yy] = meshgrid(0:n-1,0:m-1);
- x = min(x(:)) + xx*(max(x(:))-min(x(:)))/n;
- y = min(y(:)) + yy*(max(y(:))-min(y(:)))/m;
- if nargin == 3
- c = z;
- end
- if any(size(c) ~= size(z))
- error('Invalid input argument.')
- end
- if any(size(z) ~= size(x)) | any(size(z) ~= size(y))
- error('Invalid input argument.')
- end
- end
- if isstr(c)
- error('Invalid input argument.')
- end
-
- % Define position of curtains
- zref = min(min(z(finite(z))));
-
- % Define new x,y,z and then call mesh.
- zrow = zref*ones(1,n); zcol = zref*ones(m,1);
-
- newZ = [zref,zrow,zref;zcol,z,zcol;zref,zrow,zref];
- newX = [x(1,1),x(1,:),x(1,n);x(:,1),x,x(:,n);x(m,1),x(m,:),x(m,n)];
- newY = [y(1,1),y(1,:),y(1,n);y(:,1),y,y(:,n);y(m,1),y(m,:),y(m,n)];
-
- if (nargin==1) | (nargin==3),
- hm=mesh(newX,newY,newZ);
- else
- if size(c)==size(z), % Expand size of color matrix
- c = [c(1,1),c(1,:),c(1,n);c(:,1),c,c(:,n);c(m,1),c(m,:),c(m,n)];
- end
- hm=mesh(newX,newY,newZ,c);
- end
- if nargout > 0
- h = hm;
- end
-
-