2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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 |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
245
|
19 |
3449
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} __plr__ (@var{theta}, @var{rho}, @var{fmt}) |
|
22 ## @end deftypefn |
3402
|
23 |
2314
|
24 ## Author: jwe |
|
25 |
2315
|
26 function __plr__ (theta, rho, fmt) |
4
|
27 |
|
28 if (nargin == 1) |
|
29 [nr, nc] = size (theta); |
|
30 if (nr == 1) |
1518
|
31 theta = theta.'; |
4
|
32 tmp = nr; |
|
33 nr = nc; |
|
34 nc = tmp; |
|
35 endif |
|
36 theta_i = imag (theta); |
934
|
37 if (any (theta_i)) |
4
|
38 rho = theta_i; |
|
39 theta = real (theta); |
|
40 else |
|
41 rho = theta; |
|
42 theta = (1:nr)'; |
|
43 endif |
|
44 endif |
|
45 |
5115
|
46 ## Note that we call __plt__ instead of __pltXX__ below, even though |
|
47 ## we know the argument types. This is so we don't have to duplicate |
|
48 ## the functionality of __plt__ here (the __pltXX__ functions only |
|
49 ## return data and fmtstr now). |
|
50 |
4
|
51 if (nargin <= 2) |
934
|
52 if (any (imag (theta))) |
4
|
53 theta = real (theta); |
|
54 endif |
934
|
55 if (any (imag (rho))) |
4
|
56 rho = real (rho); |
|
57 endif |
4030
|
58 if (isscalar (theta)) |
|
59 if (isscalar (rho)) |
4
|
60 x = rho * cos (theta); |
|
61 y = rho * sin (theta); |
5116
|
62 __plt__ ("polar", x, y, fmt); |
4
|
63 endif |
4030
|
64 elseif (isvector (theta)) |
|
65 if (isvector (rho)) |
4
|
66 if (length (theta) != length (rho)) |
904
|
67 error ("polar: vector lengths must match"); |
4
|
68 endif |
|
69 if (rows (rho) == 1) |
1518
|
70 rho = rho.'; |
4
|
71 endif |
|
72 if (rows (theta) == 1) |
1518
|
73 theta = theta.'; |
4
|
74 endif |
|
75 x = rho .* cos (theta); |
|
76 y = rho .* sin (theta); |
5116
|
77 __plt__ ("polar", x, y, fmt); |
4030
|
78 elseif (ismatrix (rho)) |
4
|
79 [t_nr, t_nc] = size (theta); |
|
80 if (t_nr == 1) |
1518
|
81 theta = theta.'; |
4
|
82 tmp = t_nr; |
|
83 t_nr = t_nc; |
|
84 t_nc = tmp; |
|
85 endif |
|
86 [r_nr, r_nc] = size (rho); |
|
87 if (t_nr != r_nr) |
1518
|
88 rho = rho.'; |
4
|
89 tmp = r_nr; |
|
90 r_nr = r_nc; |
|
91 r_nc = tmp; |
|
92 endif |
|
93 if (t_nr != r_nr) |
904
|
94 error ("polar: vector and matrix sizes must match"); |
4
|
95 endif |
|
96 x = diag (cos (theta)) * rho; |
|
97 y = diag (sin (theta)) * rho; |
5116
|
98 __plt__ ("polar", x, y, fmt); |
4
|
99 endif |
4030
|
100 elseif (ismatrix (theta)) |
|
101 if (isvector (rho)) |
4
|
102 [r_nr, r_nc] = size (rho); |
|
103 if (r_nr == 1) |
1518
|
104 rho = rho.'; |
4
|
105 tmp = r_nr; |
|
106 r_nr = r_nc; |
|
107 r_nc = tmp; |
|
108 endif |
|
109 [t_nr, t_nc] = size (theta); |
|
110 if (r_nr != t_nr) |
1518
|
111 theta = rho.'; |
4
|
112 tmp = t_nr; |
|
113 t_nr = t_nc; |
|
114 t_nc = tmp; |
|
115 endif |
|
116 if (r_nr != t_nr) |
904
|
117 error ("polar: vector and matrix sizes must match"); |
4
|
118 endif |
|
119 diag_r = diag (r); |
|
120 x = diag_r * cos (theta); |
|
121 y = diag_r * sin (theta); |
5116
|
122 __plt__ ("polar", x, y, fmt); |
4030
|
123 elseif (ismatrix (rho)) |
4
|
124 if (size (rho) != size (theta)) |
904
|
125 error ("polar: matrix dimensions must match"); |
4
|
126 endif |
|
127 x = rho .* cos (theta); |
|
128 y = rho .* sin (theta); |
5116
|
129 __plt__ ("polar", x, y, fmt); |
4
|
130 endif |
|
131 endif |
|
132 else |
3456
|
133 usage ("__plr__ (x, y)"); |
4
|
134 endif |
|
135 |
|
136 endfunction |