Mercurial > hg > octave-max
changeset 14229:741340c02522
ribbon.m: Simplify code and return a column vector of graphics handles.
* ribbon.m: Simplify code and return a column vector of graphics handles.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Wed, 18 Jan 2012 21:17:14 -0800 |
parents | 0beb62668d69 |
children | fe65588c31b8 |
files | scripts/plot/ribbon.m |
diffstat | 1 files changed, 17 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/ribbon.m +++ b/scripts/plot/ribbon.m @@ -31,9 +31,11 @@ ## Author: Kai Habel <kai.habel at gmx.de> -function h = ribbon (x, y, width) +function h = ribbon (x, y, width = 0.75) - newplot (); + if (nargin < 1 || nargin > 3) + print_usage (); + endif if (nargin == 1) y = x; @@ -42,46 +44,42 @@ endif [nr, nc] = size (y); x = repmat ((1:nr)', 1, nc); - width = 0.75; - elseif (nargin == 2) - width = 0.75; - elseif (nargin != 3) - print_usage (); endif if (isvector (x) && isvector (y)) if (length (x) != length (y)) - error ("ribbon: in case of vectors, X and Y must have same length"); + error ("ribbon: vectors X and Y must have the same length"); else [x, y] = meshgrid (x, y); endif else - if (! size_equal(x, y)) - error ("ribbon: in case of matrices, X and Y must have same size"); + if (! size_equal (x, y)) + error ("ribbon: matrices X and Y must have the same size"); endif endif + newplot (); + [nr, nc] = size (y); - tmp = zeros (1, nc); + htmp = zeros (nc, 1); for c = nc:-1:1 zz = [y(:,c), y(:,c)]; yy = x(:,c); xx = [c - width / 2, c + width / 2]; [xx, yy] = meshgrid (xx, yy); - cc = ones (size (zz)) * c; - tmp(c) = surface (xx, yy, zz, cc); + cc = repmat (c, size (zz)); + htmp(c) = surface (xx, yy, zz, cc); endfor - ax = get (tmp(c), "parent"); - if (! ishold ()) - set (ax, "view", [-37.5, 30], "box", "off", "xgrid", "on", - "ygrid", "on", "zgrid", "on"); + ax = get (htmp(1), "parent"); + set (ax, "view", [-37.5, 30], "box", "off", + "xgrid", "on", "ygrid", "on", "zgrid", "on"); endif if (nargout > 0) - h = tmp; + h = htmp; endif endfunction @@ -93,3 +91,4 @@ %! [x, y] = meshgrid (x, y); %! ribbon (y, z); +%!FIXME: Could have some input validation tests here