# HG changeset patch # User Carnë Draug # Date 1458669783 0 # Node ID 86d8801a14ddfbc645a1504aae90c8923a2406a8 # Parent 27f2881598fa7c543d5746f7d8219a0f0e616fd0 ribbon: support specifying X as vector to be repeated for each column in Y. * plot/draw/ribbon.m: X can be a vector with same number of elements as rows in Y. Add support. Also reduce code for (nargin == 1) case so the whole logic of repmat is in a single place. diff -r 27f2881598fa -r 86d8801a14dd scripts/plot/draw/ribbon.m --- a/scripts/plot/draw/ribbon.m Tue Mar 22 17:57:28 2016 +0000 +++ b/scripts/plot/draw/ribbon.m Tue Mar 22 18:03:03 2016 +0000 @@ -24,9 +24,13 @@ ## @deftypefnx {} {@var{h} =} ribbon (@dots{}) ## Draw a ribbon plot for the columns of @var{y} vs. @var{x}. ## +## If @var{x} is omitted, a vector containing the row numbers is assumed +## (@code{1:rows (Y)}). Alternatively, @var{x} can also be a vector with +## same number of elements as rows of @var{y} in which case the same +## @var{x} is used for each column of @var{y}. +## ## The optional parameter @var{width} specifies the width of a single ribbon -## (default is 0.75). If @var{x} is omitted, a vector containing the -## row numbers is assumed (@code{1:rows (Y)}). +## (default is 0.75). ## ## If the first argument @var{hax} is an axes handle, then plot into this axis, ## rather than the current axes returned by @code{gca}. @@ -51,8 +55,7 @@ if (isvector (y)) y = y(:); endif - [nr, nc] = size (y); - x = repmat ((1:nr)', 1, nc); + x = 1:rows(y); width = 0.75; elseif (nargin == 2) x = varargin{1}; @@ -64,16 +67,12 @@ width = varargin{3}; endif - if (isvector (x) && isvector (y)) - if (length (x) != length (y)) - error ("ribbon: vectors X and Y must have the same length"); + if (! size_equal (x, y)) + if (! isvector (x) || rows (y) != numel (x)) + error (["ribbon: X must have the same dimensions as Y or be a " ... + "vector with the same number of rows as Y"]); endif - x = x(:); - y = y(:); - else - if (! size_equal (x, y)) - error ("ribbon: matrices X and Y must have the same size"); - endif + x = repmat (x(:), 1, columns (y)); endif oldfig = [];