# HG changeset patch # User jwe # Date 1198100342 0 # Node ID 9af6f0a214ee3088b47bb9541ba22a3bc77bd081 # Parent fcc6d853df9e180356e59cb8c04e3cf89f6c5ca3 [project @ 2007-12-19 21:39:02 by jwe] diff -r fcc6d853df9e -r 9af6f0a214ee scripts/ChangeLog --- a/scripts/ChangeLog Wed Dec 19 21:27:23 2007 +0000 +++ b/scripts/ChangeLog Wed Dec 19 21:39:02 2007 +0000 @@ -1,3 +1,8 @@ +2007-12-19 Alexander Barth + Peter A. Gustafson + + * scripts/contourc.m: Allow usage of irregular spaced x, y data. + 2007-12-19 John W. Eaton * miscellaneous/edit.m: New function. diff -r fcc6d853df9e -r 9af6f0a214ee scripts/plot/contour.m --- a/scripts/plot/contour.m Wed Dec 19 21:27:23 2007 +0000 +++ b/scripts/plot/contour.m Wed Dec 19 21:39:02 2007 +0000 @@ -49,7 +49,7 @@ ## @seealso{contourc, patch, plot} ## @end deftypefn -## Author: shaia +## Author: Shai Ayal function [c, h] = contour (varargin) @@ -74,3 +74,9 @@ %!demo %! [x, y, z] = peaks (); %! contour (x, y, z); + +%!demo +%! [th, r] = meshgrid (linspace (0, 2*pi, 64), 0:.05:0.9); +%! [X, Y] = pol2cart (th, r); +%! f = ((X + i*Y).^4 - 1).^(1/4); +%! contour(X, Y, abs(f), 16) diff -r fcc6d853df9e -r 9af6f0a214ee scripts/plot/contourc.m --- a/scripts/plot/contourc.m Wed Dec 19 21:27:23 2007 +0000 +++ b/scripts/plot/contourc.m Wed Dec 19 21:39:02 2007 +0000 @@ -55,20 +55,22 @@ ## @seealso{contour} ## @end deftypefn -## Author: shaia +## Author: Shai Ayal function [c, lev] = contourc (varargin) if (nargin == 1) vn = 10; z = varargin{1}; - x = 1:size(z,2); - y = 1:size(z,1); + [nr, nc] = size (z); + x = 1:nc; + y = 1:nr; elseif (nargin == 2) vn = varargin{2}; z = varargin{1}; - x = 1:size(z,2); - y = 1:size(z,1); + [nr, nc] = size (z); + x = 1:nc; + y = 1:nr; elseif (nargin == 3) vn = 10; x = varargin{1}; @@ -89,25 +91,42 @@ vv = unique (sort (vn)); endif - ## Vectorize the x,y vectors, assuming they are output from meshgrid. - if (! isvector (x)) - x = x(1,:); - endif + if (isvector (x) && isvector (y)) + c = __contourc__ (x(:)', y(:)', z, vv); + else + ## Indexes x,y for the purpose of __contourc__. + ii = 1:size (z,2); + jj = 1:size (z,1); + + ## Now call __contourc__ for the real work... + c = __contourc__ (ii, jj, z, vv); + + ## Map the contour lines from index space (i,j) back + ## to the original grid (x,y) + i = 1; - if (! isvector (y)) - y = y(:,1); - endif + while (i < size (c,2)) + clen = c(2, i); + ind = i + [1 : clen]; - ## Make everyone the right dimensions. - if (size (x, 2) == 1) - x = x'; + ci = c(1, ind); + cj = c(2,ind); + + ## due to rounding errors some elements of ci and cj + ## can fall out of the range of ii and jj and interp2 would + ## return NA for those values. + ## The permitted range is enforced here: + + ci = max (ci, 1); ci = min (ci, size (z, 2)); + cj = max (cj, 1); cj = min (cj, size (z, 1)); + + c(1, ind) = interp2 (ii, jj, x, ci, cj); + c(2, ind) = interp2 (ii, jj, y, ci, cj); + + i = i + clen + 1; + endwhile endif - if (size (y, 2) == 1) - y = y'; - endif - - ## Now call __contourc__ for the real work... - c = __contourc__ (x, y, z, vv); + if (nargout == 2) lev = vv; endif diff -r fcc6d853df9e -r 9af6f0a214ee scripts/plot/contourf.m --- a/scripts/plot/contourf.m Wed Dec 19 21:27:23 2007 +0000 +++ b/scripts/plot/contourf.m Wed Dec 19 21:39:02 2007 +0000 @@ -55,7 +55,7 @@ ## @end deftypefn ## Author: Kai Habel -## Author: shaia +## Author: Shai Ayal function varargout = contourf (varargin) @@ -258,3 +258,9 @@ %!demo %! [x, y, z] = peaks (50); %! contourf (x, y, z, -7:9) + +%!demo +%! [th, r] = meshgrid (linspace (0, 2*pi, 64), 0:.05:0.9); +%! [X, Y] = pol2cart (th, r); +%! f = ((X + i*Y).^4 - 1).^(1/4); +%! contourf(X, Y, abs(f), 16)