Mercurial > hg > octave-lojdl
changeset 13235:7b3afe09680b
allow line function to accept matrix arguments
* __line__.m: Plot columns from matrix arguments.
If no data arguments are given, set default values.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 27 Sep 2011 02:06:25 -0400 |
parents | e066d173aae6 |
children | 8bb526fb3349 |
files | scripts/plot/private/__line__.m |
diffstat | 1 files changed, 59 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/private/__line__.m +++ b/scripts/plot/private/__line__.m @@ -49,19 +49,69 @@ print_usage ("line"); endif - data_args = {}; - if (num_data_args > 1) - data_args(1:4) = { "xdata", varargin{1}, "ydata", varargin{2} }; - if (num_data_args == 3) - data_args(5:6) = { "zdata", varargin{3} }; - endif - endif - other_args = {}; if (nvargs > num_data_args) other_args = varargin(num_data_args+1:end); endif - h = __go_line__ (p, data_args{:}, other_args{:}); + nlines = 0; + nvecpts = 0; + ismat = false (1, 3); + for i = 1:num_data_args + tmp = varargin{i}(:,:); + if (isvector (tmp)) + nlines = max (1, nlines); + if (! isscalar (tmp)) + if (nvecpts == 0) + nvecpts = numel (tmp); + elseif (nvecpts != numel (tmp)) + error ("line: data size mismatch"); + endif + endif + else + ismat(i) = true; + nlines = max (columns (tmp), nlines); + endif + varargin{i} = tmp; + endfor + + if (num_data_args == 0) + varargin = {[0, 1], [0, 1]}; + num_data_args = 2; + nlines = 1; + nvecpts = 2; + endif + + handles = zeros (nlines, 1); + + data = cell (1, 3); + + if (num_data_args > 1) + data(1) = varargin{1}; + data(2) = varargin{2}; + if (num_data_args == 3) + data(3) = varargin{3}; + endif + endif + + data_args = reshape ({"xdata", "ydata", "zdata"; data{:}}, [1, 6]); + mask = reshape ([false(1,3); ismat], [1, 6]); + + for i = 1:nlines + tmp = data(ismat); + if (! size_equal (tmp) || any (nvecpts != cellfun ("size", tmp, 1))) + error ("line: data size_mismatch"); + endif + + data_args(mask) = cellfun (@(x) x(:,i), data(ismat), + "uniformoutput", false); + + handles(i) = __go_line__ (p, data_args{:}, other_args{:}); + + endfor + + if (nargout > 0) + h = handles; + endif endfunction