home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / PLOTXYZ.DI$ / MESHZ.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  2.2 KB  |  88 lines

  1. function h=meshz(x,y,z,c)
  2. %MESHZ    3-D mesh with reference plane.
  3. %    MESHZ(...) is the same as MESH(...) except that a "curtain" or
  4. %    reference plane is drawn beneath.
  5. %
  6. %    This routine only works for surfaces defined on a rectangular
  7. %    grid.  The matrices X and Y define the axis limits only.
  8. %
  9. %    See also MESH.
  10.  
  11. %     Clay M. Thompson 3-20-91
  12. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  13.  
  14. error(nargchk(1,4,nargin));
  15.  
  16. if nargin==1,  % Generate x,y matrices for surface z.
  17.   if min(size(x)) == 1 | isstr(x)
  18.       error('Invalid input argument.')
  19.   end
  20.   z = x;
  21.   [m,n] = size(z);
  22.   [x,y] = meshgrid(0:n-1,0:m-1);
  23.   c = z;
  24.  
  25. elseif nargin==2,
  26.   if isstr(x) | isstr(y)
  27.     error('Invalid input argument.')
  28.   end
  29.   if min(size(x)) == 1 | min(size(y)) == 1
  30.       error('Invalid input argument.')
  31.   end
  32.   z = x; c = y;
  33.   [m,n] = size(z);
  34.   [x,y] = meshgrid(0:n-1,0:m-1);
  35.   if any(size(c) ~= size(z))
  36.       error('Invalid input argument.')
  37.   end
  38.  
  39. elseif nargin>=3,
  40.   if isstr(x) | isstr(y) | isstr(z)
  41.       error('Invalid input argument.')
  42.   end
  43.   [m,n] = size(z);
  44.   [mx,nx] = size(x);
  45.   [my,ny] = size(y);
  46.   if m == 1 | n == 1
  47.       error('Invalid input argument.')
  48.   end
  49.   [xx,yy] = meshgrid(0:n-1,0:m-1);
  50.   x = min(x(:)) + xx*(max(x(:))-min(x(:)))/n;
  51.   y = min(y(:)) + yy*(max(y(:))-min(y(:)))/m;
  52.   if nargin == 3
  53.     c = z;
  54.   end
  55.   if any(size(c) ~= size(z))
  56.       error('Invalid input argument.')
  57.   end
  58.   if any(size(z) ~= size(x)) | any(size(z) ~= size(y))
  59.       error('Invalid input argument.')
  60.   end
  61. end
  62. if isstr(c)
  63.       error('Invalid input argument.')
  64. end
  65.  
  66. % Define position of curtains
  67. zref = min(min(z(finite(z))));
  68.  
  69. % Define new x,y,z and then call mesh.
  70. zrow = zref*ones(1,n); zcol = zref*ones(m,1);
  71.  
  72. newZ = [zref,zrow,zref;zcol,z,zcol;zref,zrow,zref];
  73. newX = [x(1,1),x(1,:),x(1,n);x(:,1),x,x(:,n);x(m,1),x(m,:),x(m,n)];
  74. newY = [y(1,1),y(1,:),y(1,n);y(:,1),y,y(:,n);y(m,1),y(m,:),y(m,n)];
  75.  
  76. if (nargin==1) | (nargin==3),
  77.   hm=mesh(newX,newY,newZ);
  78. else
  79.   if size(c)==size(z),  % Expand size of color matrix
  80.     c = [c(1,1),c(1,:),c(1,n);c(:,1),c,c(:,n);c(m,1),c(m,:),c(m,n)];
  81.   end
  82.   hm=mesh(newX,newY,newZ,c);
  83. end
  84. if nargout > 0
  85.     h = hm;
  86. end
  87.  
  88.