home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / plot / contour.m < prev    next >
Text File  |  1998-11-10  |  3KB  |  104 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. ## usage: contour (z, n, x, y)
  21. ##
  22. ## See also: plot, semilogx, semilogy, loglog, polar, mesh, contour,
  23. ##           bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title
  24.  
  25. ## Author: jwe
  26.  
  27. function contour (z, n, x, y)
  28.  
  29.   if (nargin == 1)
  30.     n = 10;
  31.   endif
  32.  
  33.   ## XXX FIXME XXX -- these plot states should really just be set
  34.   ## temporarily, probably inside an unwind_protect block, but there is
  35.   ## no way to determine their current values.
  36.  
  37.   if (nargin == 1 || nargin == 2)
  38.     if (is_matrix (z))
  39.       gset nosurface;
  40.       gset contour;
  41.       gset cntrparam bspline;
  42.       if (is_scalar (n))
  43.     command = sprintf ("gset cntrparam levels %d", n);
  44.       elseif (is_vector (n))
  45.     tmp = sprintf ("%f", n(1));
  46.     for i = 2:length (n)
  47.       tmp = sprintf ("%s, %f", tmp, n(i));
  48.     endfor
  49.     command = sprintf ("gset cntrparam levels discrete %s", tmp);
  50.       endif
  51.       eval (command);
  52.       gset noparametric;
  53.       gset view 0, 0, 1, 1;
  54.       gsplot z w l 1;
  55.     else
  56.       error ("contour: argument must be a matrix");
  57.     endif
  58.   elseif (nargin == 4)
  59.     if (is_vector (x) && is_vector (y) && is_matrix (z))
  60.       xlen = length (x);
  61.       ylen = length (y);
  62.       if (xlen == rows (z) && ylen == columns (z))
  63.         if (rows (x) == 1)
  64.           x = x';
  65.         endif
  66.         len = 3 * ylen;
  67.         zz = zeros (xlen, len);
  68.         k = 1;
  69.         for i = 1:3:len
  70.           zz(:,i)   = x;
  71.           zz(:,i+1) = y(k) * ones (xlen, 1);
  72.           zz(:,i+2) = z(:,k);
  73.           k++;
  74.         endfor
  75.         gset nosurface;
  76.         gset contour;
  77.         gset cntrparam bspline;
  78.     if (is_scalar (n))
  79.           command = sprintf ("gset cntrparam levels %d", n);
  80.     elseif (is_vector (n))
  81.       tmp = sprintf ("%f", n(1));
  82.       for i = 2:length (n)
  83.         tmp = sprintf ("%s, %f", tmp, n(i));
  84.       endfor
  85.       command = sprintf ("gset cntrparam levels discrete %s", tmp);
  86.     endif
  87.         eval (command);
  88.     gset parametric;
  89.         gset view 0, 0, 1, 1;
  90.     gsplot zz w l 1;
  91.       else
  92.         msg = "contour: rows (z) must be the same as length (x) and";
  93.         msg = sprintf ("%s\ncolumns (z) must be the same as length (y)", msg);
  94.         error (msg);
  95.       endif
  96.     else
  97.       error ("contour: x and y must be vectors and z must be a matrix");
  98.     endif
  99.   else
  100.     usage ("contour (z, levels, x, y)");
  101.   endif
  102.  
  103. endfunction
  104.