# HG changeset patch # User Ben Abbott # Date 1333754476 14400 # Node ID 8150ccfffa22e215b822123c57a6d91e3d4347de # Parent ad2ff36996b87e4b985c4881bb6ead976d65e572 Apply broadcasting to inputs of line(). * __line__.m: Use broadcasting the match the sizes of inputs. * line.m: Add demo. diff --git a/scripts/plot/line.m b/scripts/plot/line.m --- a/scripts/plot/line.m +++ b/scripts/plot/line.m @@ -43,6 +43,21 @@ endfunction +%!demo +%! clf +%! x = 0:0.3:10; +%! y1 = cos (x); +%! y2 = sin (x); +%! subplot (3, 1, 1) +%! args = {"color", "b", "marker", "s"}; +%! line ([x(:), x(:)], [y1(:), y2(:)], args{:}) +%! title ("Test broadcasting for line()") +%! subplot (3, 1, 2) +%! line (x(:), [y1(:), y2(:)], args{:}) +%! subplot (3, 1, 3) +%! line ([x(:), x(:)+pi/2], y1(:), args{:}) +%! xlim ([0 10]) + %!test %! hf = figure ("visible", "off"); %! unwind_protect diff --git a/scripts/plot/private/__line__.m b/scripts/plot/private/__line__.m --- a/scripts/plot/private/__line__.m +++ b/scripts/plot/private/__line__.m @@ -46,7 +46,15 @@ endif if (num_data_args > 0 && ! size_equal (varargin{1:num_data_args})) - error ("line: number of X, Y, and Z points must be equal"); + n = 1:num_data_args; + m = cellfun (@numel, varargin(1:num_data_args)); + [~, m] = max (m); + b = ones (size (varargin{m(1)})); + try + varargin(n) = cellfun (@(x) bsxfun (@times, b, x), varargin(n), "uniformoutput", false); + catch + error ("line: number of X, Y, and Z points must be equal"); + end_try_catch endif if (rem (nvargs - num_data_args, 2) != 0)