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 |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, 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 |
|
46 if (nargin <= 2) |
934
|
47 if (any (imag (theta))) |
4
|
48 theta = real (theta); |
|
49 endif |
934
|
50 if (any (imag (rho))) |
4
|
51 rho = real (rho); |
|
52 endif |
4030
|
53 if (isscalar (theta)) |
|
54 if (isscalar (rho)) |
4
|
55 x = rho * cos (theta); |
|
56 y = rho * sin (theta); |
2315
|
57 __plt2ss__ (x, y, fmt); |
4
|
58 endif |
4030
|
59 elseif (isvector (theta)) |
|
60 if (isvector (rho)) |
4
|
61 if (length (theta) != length (rho)) |
904
|
62 error ("polar: vector lengths must match"); |
4
|
63 endif |
|
64 if (rows (rho) == 1) |
1518
|
65 rho = rho.'; |
4
|
66 endif |
|
67 if (rows (theta) == 1) |
1518
|
68 theta = theta.'; |
4
|
69 endif |
|
70 x = rho .* cos (theta); |
|
71 y = rho .* sin (theta); |
2315
|
72 __plt2vv__ (x, y, fmt); |
4030
|
73 elseif (ismatrix (rho)) |
4
|
74 [t_nr, t_nc] = size (theta); |
|
75 if (t_nr == 1) |
1518
|
76 theta = theta.'; |
4
|
77 tmp = t_nr; |
|
78 t_nr = t_nc; |
|
79 t_nc = tmp; |
|
80 endif |
|
81 [r_nr, r_nc] = size (rho); |
|
82 if (t_nr != r_nr) |
1518
|
83 rho = rho.'; |
4
|
84 tmp = r_nr; |
|
85 r_nr = r_nc; |
|
86 r_nc = tmp; |
|
87 endif |
|
88 if (t_nr != r_nr) |
904
|
89 error ("polar: vector and matrix sizes must match"); |
4
|
90 endif |
|
91 x = diag (cos (theta)) * rho; |
|
92 y = diag (sin (theta)) * rho; |
2315
|
93 __plt2vm__ (x, y, fmt); |
4
|
94 endif |
4030
|
95 elseif (ismatrix (theta)) |
|
96 if (isvector (rho)) |
4
|
97 [r_nr, r_nc] = size (rho); |
|
98 if (r_nr == 1) |
1518
|
99 rho = rho.'; |
4
|
100 tmp = r_nr; |
|
101 r_nr = r_nc; |
|
102 r_nc = tmp; |
|
103 endif |
|
104 [t_nr, t_nc] = size (theta); |
|
105 if (r_nr != t_nr) |
1518
|
106 theta = rho.'; |
4
|
107 tmp = t_nr; |
|
108 t_nr = t_nc; |
|
109 t_nc = tmp; |
|
110 endif |
|
111 if (r_nr != t_nr) |
904
|
112 error ("polar: vector and matrix sizes must match"); |
4
|
113 endif |
|
114 diag_r = diag (r); |
|
115 x = diag_r * cos (theta); |
|
116 y = diag_r * sin (theta); |
2315
|
117 __plt2mv__ (x, y, fmt); |
4030
|
118 elseif (ismatrix (rho)) |
4
|
119 if (size (rho) != size (theta)) |
904
|
120 error ("polar: matrix dimensions must match"); |
4
|
121 endif |
|
122 x = rho .* cos (theta); |
|
123 y = rho .* sin (theta); |
2315
|
124 __plt2mm__ (x, y, fmt); |
4
|
125 endif |
|
126 endif |
|
127 else |
3456
|
128 usage ("__plr__ (x, y)"); |
4
|
129 endif |
|
130 |
|
131 endfunction |