Mercurial > hg > octave-nkf
annotate scripts/plot/private/__line__.m @ 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 | fd0a3ac60b0e |
children | 7467e90271f4 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2005-2011 John W. Eaton |
6405 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6405 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6405 | 18 |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8078
diff
changeset
|
19 ## -*- texinfo -*- |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8078
diff
changeset
|
20 ## @deftypefn {Function File} {@var{h} =} __line__ (@var{p}, @dots{}) |
6895 | 21 ## Undocumented internal function. |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8078
diff
changeset
|
22 ## @end deftypefn |
6895 | 23 |
24 ## __line__ (p, x, y, z) | |
25 ## Create line object from x, y, and z with parent p. | |
6405 | 26 ## Return handle to line object. |
27 | |
28 ## Author: jwe | |
29 | |
30 function h = __line__ (p, varargin) | |
31 | |
32 if (nargin < 1) | |
33 print_usage (); | |
34 endif | |
35 | |
36 nvargs = numel (varargin); | |
37 | |
38 if (nvargs > 1 && isnumeric (varargin{1}) && isnumeric (varargin{2})) | |
39 if (nvargs > 2 && isnumeric (varargin{3})) | |
40 num_data_args = 3; | |
41 else | |
42 num_data_args = 2; | |
43 endif | |
44 else | |
45 num_data_args = 0; | |
46 endif | |
47 | |
8078
4665276ff7f6
correctly plot matrices in plot3
David Bateman <dbateman@free.fr>
parents:
7277
diff
changeset
|
48 if (rem (nvargs - num_data_args, 2) != 0) |
6405 | 49 print_usage ("line"); |
50 endif | |
51 | |
7277 | 52 other_args = {}; |
6405 | 53 if (nvargs > num_data_args) |
7277 | 54 other_args = varargin(num_data_args+1:end); |
6405 | 55 endif |
56 | |
13235
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
57 nlines = 0; |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
58 nvecpts = 0; |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
59 ismat = false (1, 3); |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
60 for i = 1:num_data_args |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
61 tmp = varargin{i}(:,:); |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
62 if (isvector (tmp)) |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
63 nlines = max (1, nlines); |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
64 if (! isscalar (tmp)) |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
65 if (nvecpts == 0) |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
66 nvecpts = numel (tmp); |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
67 elseif (nvecpts != numel (tmp)) |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
68 error ("line: data size mismatch"); |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
69 endif |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
70 endif |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
71 else |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
72 ismat(i) = true; |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
73 nlines = max (columns (tmp), nlines); |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
74 endif |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
75 varargin{i} = tmp; |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
76 endfor |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
77 |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
78 if (num_data_args == 0) |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
79 varargin = {[0, 1], [0, 1]}; |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
80 num_data_args = 2; |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
81 nlines = 1; |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
82 nvecpts = 2; |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
83 endif |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
84 |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
85 handles = zeros (nlines, 1); |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
86 |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
87 data = cell (1, 3); |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
88 |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
89 if (num_data_args > 1) |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
90 data(1) = varargin{1}; |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
91 data(2) = varargin{2}; |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
92 if (num_data_args == 3) |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
93 data(3) = varargin{3}; |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
94 endif |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
95 endif |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
96 |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
97 data_args = reshape ({"xdata", "ydata", "zdata"; data{:}}, [1, 6]); |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
98 mask = reshape ([false(1,3); ismat], [1, 6]); |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
99 |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
100 for i = 1:nlines |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
101 tmp = data(ismat); |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
102 if (! size_equal (tmp) || any (nvecpts != cellfun ("size", tmp, 1))) |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
103 error ("line: data size_mismatch"); |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
104 endif |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
105 |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
106 data_args(mask) = cellfun (@(x) x(:,i), data(ismat), |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
107 "uniformoutput", false); |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
108 |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
109 handles(i) = __go_line__ (p, data_args{:}, other_args{:}); |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
110 |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
111 endfor |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
112 |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
113 if (nargout > 0) |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
114 h = handles; |
7b3afe09680b
allow line function to accept matrix arguments
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
115 endif |
7277 | 116 |
6405 | 117 endfunction |