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

  1. function hout = slice(x,y,z,v,sx,sy,sz,nx)
  2. %SLICE    Volumetric slice plot.
  3. %    SLICE(V,sx,sy,sz,nx) draws slices of volume V at the locations specified
  4. %    in the index vectors sx, sy, and sz.  nx is the number of rows in
  5. %    volume array V.
  6. %
  7. %    SLICE(X,Y,Z,V,sx,sy,sz,nx) draws the slices for the volume locations
  8. %    specified by the triples (X(i),Y(i),Z(i)).
  9. %
  10. %    For example, to evaluate the function  x*exp(-x^2-y^2-z^2) over the 
  11. %    range  -2 < x < 2,  -2 < y < 2,- 2 < z < 2,
  12. %
  13. %       [x,y,z] = meshgrid(-2:.2:2, -2:.2:2, -2:.2:2);
  14. %       v = x .* exp(-x.^2 - y.^2 - z.^2);
  15. %       slice(v,[5 15 21],21,[1 10],21)
  16. %
  17. %    SLICE returns a vector of handles to SURFACE objects.
  18.  
  19. %     J.N. Little 1-23-92
  20. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  21.  
  22. cax = newplot;
  23. next = lower(get(cax,'NextPlot'));
  24. hold_state = ishold;
  25.  
  26. if nargin == 5
  27.     nx = sx; sz = v; sy = z; sx = y; v = x;
  28.     [m,nz] = size(v);
  29.     ny = m/nx;
  30.     [x,y,z] = meshgrid(1:nx,1:ny,1:nz);
  31. end
  32. [m,nz] = size(v);
  33. ny = m/nx;
  34.  
  35. if min(size(x)) == 1
  36.     [x,y,z] = meshgrid(x,y,z);
  37. end
  38.  
  39. h = [];
  40. for i = 1:length(sx)
  41.     n = sx(i);
  42.     h = [h; surface(x((1:ny)+ny*(n-1),:),y((1:ny)+ny*(n-1),:),z((1:ny)+ny*(n-1),:),v((1:ny)+ny*(n-1),:))];
  43. end
  44.  
  45. for i = 1:length(sy)
  46.     n = sy(i);
  47.     h = [h; surface(x(n:ny:m,:),y(n:ny:m,:),z(n:ny:m,:),v(n:ny:m,:))];
  48. end
  49.  
  50. for i = 1:length(sz)
  51.     n = sz(i);
  52.     h = [h; surface(reshape(x(:,n),nx,ny),reshape(y(:,n),nx,ny),...
  53.         reshape(z(:,n),nx,ny),reshape(v(:,n),nx,ny))];
  54. end
  55.  
  56. if nargout > 0
  57.     hout = h;
  58. end
  59. if ~hold_state
  60.     view(3)
  61. end
  62. caxis([min(min(v)) max(max(v))])
  63.