Mercurial > hg > octave-lyh
changeset 14535:8150ccfffa22
Apply broadcasting to inputs of line().
* __line__.m: Use broadcasting the match the sizes of inputs.
* line.m: Add demo.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Fri, 06 Apr 2012 19:21:16 -0400 |
parents | ad2ff36996b8 |
children | 6d5c951ec520 |
files | scripts/plot/line.m scripts/plot/private/__line__.m |
diffstat | 2 files changed, 24 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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)