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

  1. function h=surfc(x,y,z,c)
  2. %SURFC    Combination SURF/CONTOUR plot.
  3. %    SURFC(...) is the same as SURF(...) except that a contour plot
  4. %    is drawn beneath the surface.
  5. %
  6. %    Because CONTOUR does not handle irregularly spaced data, this 
  7. %    routine only works for surfaces defined on a rectangular grid.
  8. %    The matrices or vectors X and Y define the axis limits only.
  9. %
  10. %    See also SURF.
  11.  
  12. %    Clay M. Thompson 4-10-91
  13. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  14.  
  15. error(nargchk(1,4,nargin));
  16.  
  17. if nargin==1,  % Generate x,y matrices for surface z.
  18.   z = x;
  19.   [m,n] = size(z);
  20.   [x,y] = meshgrid(1:n,1:m);
  21.  
  22. elseif nargin==2,
  23.   z = x; c = y;
  24.   [m,n] = size(z);
  25.   [x,y] = meshgrid(1:n,1:m);
  26.  
  27. end
  28.  
  29. if min(size(z))==1,
  30.   error('The surface Z must contain more than one row or column.');
  31. end
  32.  
  33. % Determine state of system
  34. cax = newplot;
  35. next = lower(get(cax,'NextPlot'));
  36. hold_state = ishold;
  37.  
  38. % Plot surface
  39. if nargin==2 | nargin==4,
  40.   hs=surf(x,y,z,c);
  41. else
  42.   hs=surf(x,y,z);
  43. end
  44.  
  45. hold on;
  46.  
  47. a = get(gca,'zlim');
  48.  
  49. zpos = a(1); % Always put contour below plot.
  50.  
  51. % Get D contour data
  52. [cc,hh] = contour3(x,y,z);
  53.  
  54. %%% size zpos to match the data
  55.  
  56. for i = 1:length(hh)
  57.         zz = get(hh(i),'Zdata');
  58.         set(hh(i),'Zdata',zpos*ones(size(zz)));
  59. end
  60.  
  61. if ~hold_state, set(cax,'NextPlot',next); end
  62. if nargout > 0
  63.     h = [hs; hh(:)];
  64. end
  65.