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