# HG changeset patch # User jwe # Date 1036210333 0 # Node ID c1438a47fd5eaa8576d8b335df8e3a74efddac66 # Parent c3bb286a18a9a2be3d1e9cd61c4cee81d5969dbd [project @ 2002-11-02 04:12:13 by jwe] diff --git a/scripts/plot/contour.m b/scripts/plot/contour.m --- a/scripts/plot/contour.m +++ b/scripts/plot/contour.m @@ -1,4 +1,4 @@ -## Copyright (C) 1996, 1997 John W. Eaton +## Copyright (C) 1996, 1997, 2002 John W. Eaton ## ## This file is part of Octave. ## @@ -54,60 +54,78 @@ tmp = sprintf ("%s, %f", tmp, n(i)); endfor command = sprintf ("gset cntrparam levels discrete %s", tmp); + else + error ("contour: levels must be a scalar or vector") ; endif eval (command); gset noparametric; gset view 0, 0, 1, 1; gsplot z w l 1; else - error ("contour: argument must be a matrix"); + error ("contour: z of contour (z, levels) must be a matrix"); endif elseif (nargin == 3 || nargin == 4) if (nargin == 3) n = 10; endif - if (isvector (x) && isvector (y) && ismatrix (z)) - xlen = length (x); - ylen = length (y); - if (xlen == columns (z) && ylen == rows (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++; + if (ismatrix (z)) + size_msg = ["contour: columns(z) must be the same as length(x) and\n" \ + "rows(z) must be the same as length(y),\n" \ + "or x, y, and z must be matrices with the same size"]; + if (isvector (x) && isvector (y)) + xlen = length (x); + ylen = length (y); + if (xlen == columns (z) && ylen == rows (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 + else + error (size_msg); + endif + else + z_size = size (z); + if (z_size == size (x) && z_size == size (y)) + nc = 3*z_size(1); + zz = zeros (z_size(2), nc); + zz(:,1:3:nc) = x'; + zz(:,2:3:nc) = y'; + zz(:,3:3:nc) = z'; + else + error (size_msg); + endif + endif + gset nosurface; + gset contour; + gset cntrparam bspline; + if (isscalar (n)) + command = sprintf ("gset cntrparam levels %d", n); + elseif (isvector (n)) + tmp = sprintf ("%f", n(1)); + for i = 2:length (n) + tmp = sprintf ("%s, %f", tmp, n(i)); endfor - gset nosurface; - gset contour; - gset cntrparam bspline; - if (isscalar (n)) - command = sprintf ("gset cntrparam levels %d", n); - elseif (isvector (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; + command = sprintf ("gset cntrparam levels discrete %s", tmp); 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); + error ("contour: levels must be a scalar or vector") ; endif + eval (command); + gset parametric; + gset view 0, 0, 1, 1; + gsplot zz w l 1; else error ("contour: x and y must be vectors and z must be a matrix"); endif else - usage ("contour (z, x, y, levels)"); + usage ("contour (x, y, z, levels) or contour (z, levels)"); endif endfunction