Mercurial > octave-nkf
comparison src/DLD-FUNCTIONS/cellfun.cc @ 5543:4d52e637a72a
[project @ 2005-11-21 16:13:47 by jwe]
author | jwe |
---|---|
date | Mon, 21 Nov 2005 16:13:47 +0000 |
parents | ed08548b9054 |
children | 2286fa5f2e5d |
comparison
equal
deleted
inserted
replaced
5542:b23c53f26aec | 5543:4d52e637a72a |
---|---|
36 #include "ov-colon.h" | 36 #include "ov-colon.h" |
37 | 37 |
38 DEFUN_DLD (cellfun, args, , | 38 DEFUN_DLD (cellfun, args, , |
39 " -*- texinfo -*-\n\ | 39 " -*- texinfo -*-\n\ |
40 @deftypefn {Lodable Function} {} cellfun (@var{name}, @var{c})\n\ | 40 @deftypefn {Lodable Function} {} cellfun (@var{name}, @var{c})\n\ |
41 @deftypefnx {Lodable Function} {} cellfun (\"size\", @var{c}, @var{k})\n\ | |
41 @deftypefnx {Lodable Function} {} cellfun (\"isclass\", @var{c}, @var{class})\n\ | 42 @deftypefnx {Lodable Function} {} cellfun (\"isclass\", @var{c}, @var{class})\n\ |
42 @deftypefnx {Lodable Function} {} cellfun (\"size\", @var{c}, @var{k})\n\ | |
43 @deftypefnx {Lodable Function} {} cellfun (@var{func}, @var{c})\n\ | 43 @deftypefnx {Lodable Function} {} cellfun (@var{func}, @var{c})\n\ |
44 \n\ | 44 \n\ |
45 Evaluate the function named @var{name} on the elements of the cell array\n\ | 45 Evaluate the function named @var{name} on the elements of the cell array\n\ |
46 @var{c}. Elements in cell_array are passed on to the named function\n\ | 46 @var{c}. Elements in @var{c} are passed on to the named function\n\ |
47 individually. The function @var{name} can be one of the functions\n\ | 47 individually. The function @var{name} can be one of the functions\n\ |
48 \n\ | 48 \n\ |
49 @table @code\n\ | 49 @table @code\n\ |
50 @item isempty\n\ | 50 @item isempty\n\ |
51 Return 1 when for non empty elements and 0 for others.\n\ | 51 Return 1 for empty elements.\n\ |
52 @item islogical\n\ | 52 @item islogical\n\ |
53 Return 1 for logical elements.\n\ | 53 Return 1 for logical elements.\n\ |
54 @item isreal\n\ | 54 @item isreal\n\ |
55 Return 1 for real elements.\n\ | 55 Return 1 for real elements.\n\ |
56 @item length\n\ | 56 @item length\n\ |
57 Return a vector of the lengths of cell elements.\n\ | 57 Return a vector of the lengths of cell elements.\n\ |
58 @item dims\n\ | 58 @item ndims\n\ |
59 Return the number of dimensions of each element.\n\ | 59 Return the number of dimensions of each element.\n\ |
60 @item prodofsize\n\ | 60 @item prodofsize\n\ |
61 Return the product of dimensions of each element.\n\ | 61 Return the product of dimensions of each element.\n\ |
62 @item size\n\ | 62 @item size\n\ |
63 Return the size along the @var{k}-th dimension.\n\ | 63 Return the size along the @var{k}-th dimension.\n\ |
76 cellfun (\"tolower(x)\", @{\"Foo\", \"Bar\", \"FooBar\"@})\n\ | 76 cellfun (\"tolower(x)\", @{\"Foo\", \"Bar\", \"FooBar\"@})\n\ |
77 @result{} ans = @{\"foo\", \"bar\", \"foobar\"@}\n\ | 77 @result{} ans = @{\"foo\", \"bar\", \"foobar\"@}\n\ |
78 @end group\n\ | 78 @end group\n\ |
79 @end example\n\ | 79 @end example\n\ |
80 \n\ | 80 \n\ |
81 @end deftypefn") | 81 @end deftypefn\n\ |
82 @seealso{isempty, islogical, isreal, length, ndims, numel, size, isclass}") | |
82 { | 83 { |
83 octave_value retval; | 84 octave_value retval; |
84 | 85 |
85 std::string name = "function"; | 86 std::string name = "function"; |
86 | 87 |
104 } | 105 } |
105 else if (args(0).is_string ()) | 106 else if (args(0).is_string ()) |
106 name = args(0).string_value (); | 107 name = args(0).string_value (); |
107 else | 108 else |
108 { | 109 { |
109 error ("cellfun: first argument must be a string"); | 110 error ("cellfun: first argument must be a string or function handle"); |
110 return retval; | 111 return retval; |
111 } | 112 } |
112 | 113 |
113 if (! args(1).is_cell ()) | 114 if (! args(1).is_cell ()) |
114 { | 115 { |
115 error ("cellfun: second argument must be a cell"); | 116 error ("cellfun: second argument must be a cell array"); |
116 | 117 |
117 return retval; | 118 return retval; |
118 } | 119 } |
119 | 120 |
120 Cell f_args = args(1).cell_value (); | 121 Cell f_args = args(1).cell_value (); |
123 | 124 |
124 if (name == "isempty") | 125 if (name == "isempty") |
125 { | 126 { |
126 boolNDArray result (f_args.dims ()); | 127 boolNDArray result (f_args.dims ()); |
127 for (int count = 0; count < k ; count++) | 128 for (int count = 0; count < k ; count++) |
128 result(count) = f_args.elem(count).is_empty(); | 129 result(count) = f_args.elem(count).is_empty (); |
129 retval = result; | 130 retval = result; |
130 } | 131 } |
131 else if (name == "islogical") | 132 else if (name == "islogical") |
132 { | 133 { |
133 boolNDArray result (f_args.dims ()); | 134 boolNDArray result (f_args.dims ()); |
144 } | 145 } |
145 else if (name == "length") | 146 else if (name == "length") |
146 { | 147 { |
147 NDArray result (f_args.dims ()); | 148 NDArray result (f_args.dims ()); |
148 for (int count= 0; count < k ; count++) | 149 for (int count= 0; count < k ; count++) |
149 result(count) = double (f_args.elem(count).numel ()); | 150 result(count) = double (f_args.elem(count).length ()); |
150 retval = result; | 151 retval = result; |
151 } | 152 } |
152 else if (name == "ndims") | 153 else if (name == "ndims") |
153 { | 154 { |
154 NDArray result (f_args.dims ()); | 155 NDArray result (f_args.dims ()); |
155 for (int count = 0; count < k ; count++) | 156 for (int count = 0; count < k ; count++) |
156 result(count) = double ((f_args.elem(count).dims ()).numel ()); | 157 result(count) = double (f_args.elem(count).ndims ()); |
157 retval = result; | 158 retval = result; |
158 } | 159 } |
159 else if (name == "prodofsize") | 160 else if (name == "prodofsize") |
160 { | 161 { |
161 NDArray result (f_args.dims ()); | 162 NDArray result (f_args.dims ()); |
162 for (int count = 0; count < k ; count++) | 163 for (int count = 0; count < k ; count++) |
163 result(count) = double ((f_args.elem(count).dims ()).numel ()); | 164 result(count) = double (f_args.elem(count).numel ()); |
164 retval = result; | 165 retval = result; |
165 } | 166 } |
166 else if (name == "size") | 167 else if (name == "size") |
167 { | 168 { |
168 if (nargin == 3) | 169 if (nargin == 3) |
185 } | 186 } |
186 retval = result; | 187 retval = result; |
187 } | 188 } |
188 } | 189 } |
189 else | 190 else |
190 error ("Not enough argument for size"); | 191 error ("not enough arguments for `size'"); |
191 } | 192 } |
192 else if (name == "isclass") | 193 else if (name == "isclass") |
193 { | 194 { |
194 if (nargin == 3) | 195 if (nargin == 3) |
195 { | 196 { |
199 result(count) = (f_args.elem(count).class_name() == class_name); | 200 result(count) = (f_args.elem(count).class_name() == class_name); |
200 | 201 |
201 retval = result; | 202 retval = result; |
202 } | 203 } |
203 else | 204 else |
204 error ("Not enough argument for isclass"); | 205 error ("not enough arguments for `isclass'"); |
205 } | 206 } |
206 else | 207 else |
207 { | 208 { |
208 std::string fcn_name; | 209 std::string fcn_name; |
209 | 210 |