home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts.fat / plot / mesh.m < prev    next >
Text File  |  1999-12-24  |  4KB  |  117 lines

  1. ## Copyright (C) 1996, 1997 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## -*- texinfo -*-
  21. ## @deftypefn {Function File} {} mesh (@var{x}, @var{y}, @var{z})
  22. ## Plot a mesh given matrices @code{x}, and @var{y} from @code{meshdom} and
  23. ## a matrix @var{z} corresponding to the @var{x} and @var{y} coordinates of
  24. ## the mesh.  If @var{x} and @var{y} are vectors, then a typical vertex
  25. ## is (@var{x}(j), @var{y}(i), @var{z}(i,j)).  Thus, columns of @var{z}
  26. ## correspond to different @var{x} values and rows of @var{z} correspond
  27. ## to different @var{y} values.
  28. ## @end deftypefn
  29.  
  30. ## See also: plot, semilogx, semilogy, loglog, polar, meshgrid, meshdom,
  31. ##           contour, bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title
  32.  
  33. ## Author: jwe
  34.  
  35. function mesh (x, y, z)
  36.  
  37.   ## XXX FIXME XXX -- the plot states should really just be set
  38.   ## temporarily, probably inside an unwind_protect block, but there is
  39.   ## no way to determine their current values.
  40.  
  41.   if (nargin == 1)
  42.     z = x;
  43.     if (is_mat (z))
  44.       gset hidden3d;
  45.       gset data style lines;
  46.       gset surface;
  47.       gset nocontour;
  48.       gset noparametric;
  49.       gset view 60, 30, 1, 1
  50.       gsplot (z');
  51.     else
  52.       error ("mesh: argument must be a matrix");
  53.     endif
  54.   elseif (nargin == 3)
  55.     if (is_vec (x) && is_vec (y) && is_mat (z))
  56.       xlen = length (x);
  57.       ylen = length (y);
  58.       if (xlen == columns (z) && ylen == rows (z))
  59.         if (rows (y) == 1)
  60.           y = y';
  61.         endif
  62.         len = 3 * xlen;
  63.         zz = zeros (ylen, len);
  64.         k = 1;
  65.         for i = 1:3:len
  66.           zz(:,i)   = x(k) * ones (ylen, 1);
  67.           zz(:,i+1) = y;
  68.           zz(:,i+2) = z(:,k);
  69.           k++;
  70.         endfor
  71.     gset hidden3d;
  72.     gset data style lines;
  73.         gset surface;
  74.         gset nocontour;
  75.     gset parametric;
  76.         gset view 60, 30, 1, 1
  77.     gsplot (zz);
  78.     gset noparametric;
  79.       else
  80.         msg = "mesh: rows (z) must be the same as length (x) and";
  81.         msg = sprintf ("%s\ncolumns (z) must be the same as length (y)", msg);
  82.         error (msg);
  83.       endif
  84.     elseif (is_mat (x) && is_mat (y) && is_mat (z))
  85.       xlen = columns (z);
  86.       ylen = rows (z);
  87.       if (xlen == columns (x) && xlen == columns (y) &&
  88.     ylen == rows (x) && ylen == rows(y))
  89.         len = 3 * xlen;
  90.         zz = zeros (ylen, len);
  91.         k = 1;
  92.         for i = 1:3:len
  93.           zz(:,i)   = x(:,k);
  94.           zz(:,i+1) = y(:,k);
  95.           zz(:,i+2) = z(:,k);
  96.           k++;
  97.         endfor
  98.     gset hidden3d;
  99.     gset data style lines;
  100.         gset surface;
  101.         gset nocontour;
  102.     gset parametric;
  103.         gset view 60, 30, 1, 1
  104.     gsplot (zz);
  105.     gset noparametric;
  106.       else
  107.         error ("mesh: x, y, and z must have same dimensions");
  108.       endif
  109.     else
  110.       error ("mesh: x and y must be vectors and z must be a matrix");
  111.     endif
  112.   else
  113.     usage ("mesh (z)");
  114.   endif
  115.  
  116. endfunction
  117.