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