6257
|
1 ## Copyright (C) 2007 John W. Eaton |
|
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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{label}) |
|
22 ## @deftypefnx {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{z}, @var{label}) |
|
23 ## Create a text object with text @var{label} at position @var{x}, |
|
24 ## @var{y}, @var{z} on the current axes. The label may be followed by |
|
25 ## property-value pairs. |
|
26 ## @end deftypefn |
|
27 |
|
28 ## Author: jwe |
|
29 |
|
30 function h = text (varargin) |
|
31 |
6405
|
32 nargs = nargin; |
|
33 offset = 0; |
|
34 |
|
35 if (nargs > 2 && isnumeric (varargin{1}) && isnumeric (varargin{2})) |
|
36 x = varargin{1}; |
|
37 y = varargin{2}; |
|
38 offset = 3; |
6257
|
39 |
|
40 if (nargin > 3 && isnumeric (varargin{3})) |
|
41 z = varargin{3}; |
|
42 offset = 4; |
|
43 else |
|
44 z = zeros (size (x)); |
|
45 offset = 3; |
|
46 endif |
|
47 |
|
48 label = varargin{offset}; |
|
49 if (ischar (label) || iscellstr (label)) |
|
50 varargin(1:offset) = []; |
|
51 if (ischar (label)) |
|
52 label = cellstr (label); |
|
53 endif |
|
54 n = numel (label); |
|
55 nx = numel (x); |
|
56 ny = numel (y); |
|
57 nz = numel (z); |
|
58 else |
|
59 error ("text: expecting label to be a character string or cell array of character strings"); |
|
60 endif |
6405
|
61 else |
|
62 x = y = z = 0; |
|
63 nx = ny = nz = 1; |
|
64 label = {""}; |
|
65 n = 1; |
|
66 endif |
6257
|
67 |
6405
|
68 if (rem (numel (varargin), 2) == 0) |
|
69 |
|
70 if (nx == ny && nx == nz) |
|
71 pos = [x(:), y(:), z(:)]; |
|
72 ca = gca (); |
|
73 tmp = zeros (n, 1); |
|
74 if (n == 1) |
|
75 label = label{1}; |
|
76 for i = 1:nx |
|
77 tmp(i) = __go_text__ (ca, "string", label, |
|
78 "position", pos(i,:), |
|
79 varargin{:}); |
|
80 endfor |
|
81 elseif (n == nx) |
|
82 for i = 1:nx |
|
83 tmp(i) = __go_text__ (ca, "string", label{i}, |
|
84 "position", pos(i,:), |
|
85 varargin{:}); |
|
86 endfor |
|
87 else |
|
88 error ("text: dimension mismatch for coordinates and label"); |
|
89 endif |
|
90 else |
|
91 error ("text: dimension mismatch for coordinates"); |
|
92 endif |
6257
|
93 |
|
94 if (nargout > 0) |
|
95 h = tmp; |
|
96 endif |
|
97 |
|
98 else |
|
99 print_usage (); |
|
100 endif |
|
101 |
|
102 endfunction |