Mercurial > hg > octave-lyh
annotate scripts/general/arrayfun.m @ 8610:85c9906abfd1
use endif and endfor instead of end
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 27 Jan 2009 23:17:37 -0500 |
parents | 55b97f709203 |
children | eb63fbe60fab |
rev | line source |
---|---|
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
1 ## Copyright (C) 2006, 2007, 2008 Bill Denney |
6422 | 2 ## |
6439 | 3 ## This file is part of Octave. |
6422 | 4 ## |
6439 | 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. | |
6439 | 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. | |
6422 | 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/>. | |
6422 | 18 |
19 ## -*- texinfo -*- | |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
20 ## @deftypefn {Function File} {} arrayfun (@var{func}, @var{a}) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
21 ## @deftypefnx {Function File} {@var{x} =} arrayfun (@var{func}, @var{a}) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
22 ## @deftypefnx {Function File} {@var{x} =} arrayfun (@var{func}, @var{a}, @var{b}, @dots{}) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
23 ## @deftypefnx {Function File} {[@var{x}, @var{y}, @dots{}] =} arrayfun (@var{func}, @var{a}, @dots{}) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
24 ## @deftypefnx {Function File} {} arrayfun (@dots{}, "UniformOutput", @var{val}) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
25 ## @deftypefnx {Function File} {} arrayfun (@dots{}, "ErrorHandler", @var{errfunc}) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
26 ## |
6439 | 27 ## Execute a function on each element of an array. This is useful for |
28 ## functions that do not accept array arguments. If the function does | |
6422 | 29 ## accept array arguments it is better to call the function directly. |
30 ## | |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
31 ## The first input argument @var{func} can be a string, a function |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
32 ## handle, an inline function or an anonymous function. The input |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
33 ## argument @var{a} can be a logic array, a numeric array, a string |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
34 ## array, a structure array or a cell array. By a call of the function |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
35 ## @command{arrayfun} all elements of @var{a} are passed on to the named |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
36 ## function @var{func} individually. |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
37 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
38 ## The named function can also take more than two input arguments, with |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
39 ## the input arguments given as third input argument @var{b}, fourth |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
40 ## input argument @var{c}, @dots{} If given more than one array input |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
41 ## argument then all input arguments must have the same sizes, for |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
42 ## example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
43 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
44 ## @example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
45 ## @group |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
46 ## arrayfun (@@atan2, [1, 0], [0, 1]) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
47 ## @result{} ans = [1.5708 0.0000] |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
48 ## @end group |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
49 ## @end example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
50 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
51 ## If the parameter @var{val} after a further string input argument |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
52 ## "UniformOutput" is set @code{true} (the default), then the named |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
53 ## function @var{func} must return a single element which then will be |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
54 ## concatenated into the return value and is of type matrix. Otherwise, |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
55 ## if that parameter is set to @code{false}, then the outputs are |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
56 ## concatenated in a cell array. For example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
57 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
58 ## @example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
59 ## @group |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
60 ## arrayfun (@@(x,y) x:y, "abc", "def", "UniformOutput", false) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
61 ## @result{} ans = |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
62 ## @{ |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
63 ## [1,1] = abcd |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
64 ## [1,2] = bcde |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
65 ## [1,3] = cdef |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
66 ## @} |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
67 ## @end group |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
68 ## @end example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
69 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
70 ## If more than one output arguments are given then the named function |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
71 ## must return the number of return values that also are expected, for |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
72 ## example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
73 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
74 ## @example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
75 ## @group |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
76 ## [A, B, C] = arrayfun (@@find, [10; 0], "UniformOutput", false) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
77 ## @result{} |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
78 ## A = |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
79 ## @{ |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
80 ## [1,1] = 1 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
81 ## [2,1] = [](0x0) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
82 ## @} |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
83 ## B = |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
84 ## @{ |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
85 ## [1,1] = 1 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
86 ## [2,1] = [](0x0) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
87 ## @} |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
88 ## C = |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
89 ## @{ |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
90 ## [1,1] = 10 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
91 ## [2,1] = [](0x0) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
92 ## @} |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
93 ## @end group |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
94 ## @end example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
95 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
96 ## If the parameter @var{errfunc} after a further string input argument |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
97 ## "ErrorHandler" is another string, a function handle, an inline |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
98 ## function or an anonymous function, then @var{errfunc} defines a |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
99 ## function to call in the case that @var{func} generates an error. |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
100 ## The definition of the function must be of the form |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
101 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
102 ## @example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
103 ## function [@dots{}] = errfunc (@var{s}, @dots{}) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
104 ## @end example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
105 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
106 ## where there is an additional input argument to @var{errfunc} |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
107 ## relative to @var{func}, given by @var{s}. This is a structure with |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
108 ## the elements "identifier", "message" and "index", giving |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
109 ## respectively the error identifier, the error message and the index of |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
110 ## the array elements that caused the error. The size of the output |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
111 ## argument of @var{errfunc} must have the same size as the output |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
112 ## argument of @var{func}, otherwise a real error is thrown. For |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
113 ## example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
114 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
115 ## @example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
116 ## @group |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
117 ## function y = ferr (s, x), y = "MyString"; endfunction |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
118 ## arrayfun (@@str2num, [1234], \ |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
119 ## "UniformOutput", false, "ErrorHandler", @@ferr) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
120 ## @result{} ans = |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
121 ## @{ |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
122 ## [1,1] = MyString |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
123 ## @} |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
124 ## @end group |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
125 ## @end example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
126 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
127 ## @seealso{cellfun, spfun, structfun} |
6422 | 128 ## @end deftypefn |
129 | |
7017 | 130 ## Author: Bill Denney <denney@seas.upenn.edu> |
131 | |
6439 | 132 function varargout = arrayfun (func, varargin) |
6422 | 133 |
134 if (nargin < 2) | |
6439 | 135 print_usage (); |
6422 | 136 endif |
137 | |
6439 | 138 ## Convert everything to cells and call cellfun (let cellfun error |
139 ## check the options in case more options come available). | |
140 sizetomatch = size (varargin{1}); | |
6422 | 141 m2cargs{1} = ones (size (varargin{1}, 1), 1); |
142 m2cargs{2} = ones (size (varargin{1}, 2), 1); | |
143 cfarg{1} = mat2cell (varargin{1}, m2cargs{:}); | |
144 stillmatches = true; | |
8358 | 145 idx = 1; |
146 len = length (varargin); | |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
147 while (stillmatches && idx < len) |
6422 | 148 idx++; |
149 thissize = size (varargin{idx}); | |
6439 | 150 if (numel (thissize) == numel (sizetomatch) |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
151 && all (thissize == sizetomatch)) |
6439 | 152 if (ischar (varargin{idx}) |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
153 && (strcmpi (varargin{idx}, "UniformOutput") |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
154 || strcmpi (varargin{idx}, "ErrorHandler"))) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
155 ## Catch these strings just in case they happen to be the same |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
156 ## size as the other input. |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
157 stillmatches = false; |
6422 | 158 else |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
159 cfarg{idx} = mat2cell (varargin{idx}, m2cargs{:}); |
6422 | 160 endif |
161 else | |
162 stillmatches = false; | |
163 endif | |
164 endwhile | |
165 | |
166 varargout = cell (max ([nargout, 1]), 1); | |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
167 if (idx >= len) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
168 [varargout{:}] = cellfun (func, cfarg{:}); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
169 else |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
170 [varargout{:}] = cellfun (func, cfarg{:}, varargin{idx:len}); |
8610
85c9906abfd1
use endif and endfor instead of end
John W. Eaton <jwe@octave.org>
parents:
8358
diff
changeset
|
171 endif |
6422 | 172 endfunction |
173 | |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
174 %% Test function to check the "Errorhandler" option |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
175 %!function [z] = arrayfunerror (S, varargin) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
176 %! z = S; |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
177 %! endfunction |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
178 %% First input argument can be a string, an inline function, a |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
179 %% function_handle or an anonymous function |
6422 | 180 %!test |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
181 %! arrayfun (@isequal, [false, true], [true, true]); %% No output argument |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
182 %!error |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
183 %! arrayfun (@isequal); %% One or less input arguments |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
184 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
185 %! A = arrayfun ("isequal", [false, true], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
186 %! assert (A, [false, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
187 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
188 %! A = arrayfun (inline ("(x == y)", "x", "y"), [false, true], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
189 %! assert (A, [false, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
190 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
191 %! A = arrayfun (@isequal, [false, true], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
192 %! assert (A, [false, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
193 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
194 %! A = arrayfun (@(x,y) isequal(x,y), [false, true], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
195 %! assert (A, [false, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
196 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
197 %% Number of input and output arguments may be greater than one |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
198 %#!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
199 %! A = arrayfun (@(x) islogical (x), false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
200 %! assert (A, true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
201 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
202 %! A = arrayfun (@(x,y,z) x + y + z, [1, 1, 1], [2, 2, 2], [3, 4, 5]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
203 %! assert (A, [6, 7, 8], 1e-16); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
204 %!test %% Two input arguments of different types |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
205 %! A = arrayfun (@(x,y) islogical (x) && ischar (y), false, "a"); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
206 %! assert (A, true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
207 %!test %% Pass another variable to the anonymous function |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
208 %! y = true; A = arrayfun (@(x) islogical (x && y), false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
209 %! assert (A, true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
210 %!test %% Three ouptut arguments of different type |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
211 %! [A, B, C] = arrayfun (@find, [10, 11; 0, 12], "UniformOutput", false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
212 %! assert (isequal (A, {true, true; [], true})); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
213 %! assert (isequal (B, {true, true; [], true})); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
214 %! assert (isequal (C, {10, 11; [], 12})); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
215 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
216 %% Input arguments can be of type logical |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
217 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
218 %! A = arrayfun (@(x,y) x == y, [false, true], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
219 %! assert (A, [false, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
220 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
221 %! A = arrayfun (@(x,y) x == y, [false; true], [true; true], "UniformOutput", true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
222 %! assert (A, [false; true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
223 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
224 %! A = arrayfun (@(x) x, [false, true, false, true], "UniformOutput", false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
225 %! assert (A, {false, true, false, true}); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
226 %!test %% Three ouptut arguments of same type |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
227 %! [A, B, C] = arrayfun (@find, [true, false; false, true], "UniformOutput", false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
228 %! assert (isequal (A, {true, []; [], true})); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
229 %! assert (isequal (B, {true, []; [], true})); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
230 %! assert (isequal (C, {true, []; [], true})); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
231 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
232 %! A = arrayfun (@(x,y) array2str (x,y), true, true, "ErrorHandler", @arrayfunerror); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
233 %! assert (isfield (A, "identifier"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
234 %! assert (isfield (A, "message"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
235 %! assert (isfield (A, "index"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
236 %! assert (isempty (A.message), false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
237 %! assert (A.index, 1); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
238 %!test %% Overwriting setting of "UniformOutput" true |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
239 %! A = arrayfun (@(x,y) array2str (x,y), true, true, \ |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
240 %! "UniformOutput", true, "ErrorHandler", @arrayfunerror); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
241 %! assert (isfield (A, "identifier"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
242 %! assert (isfield (A, "message"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
243 %! assert (isfield (A, "index"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
244 %! assert (isempty (A.message), false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
245 %! assert (A.index, 1); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
246 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
247 %% Input arguments can be of type numeric |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
248 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
249 %! A = arrayfun (@(x,y) x>y, [1.1, 4.2], [3.1, 2+6*i]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
250 %! assert (A, [false, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
251 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
252 %! A = arrayfun (@(x,y) x>y, [1.1, 4.2; 2, 4], [3.1, 2; 2, 4+2*i], "UniformOutput", true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
253 %! assert (A, [false, true; false, false]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
254 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
255 %! A = arrayfun (@(x,y) x:y, [1.1, 4], [3.1, 6], "UniformOutput", false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
256 %! assert (isequal (A{1}, [1.1, 2.1, 3.1])); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
257 %! assert (isequal (A{2}, [4, 5, 6])); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
258 %!test %% Three ouptut arguments of different type |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
259 %! [A, B, C] = arrayfun (@find, [10, 11; 0, 12], "UniformOutput", false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
260 %! assert (isequal (A, {true, true; [], true})); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
261 %! assert (isequal (B, {true, true; [], true})); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
262 %! assert (isequal (C, {10, 11; [], 12})); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
263 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
264 %! A = arrayfun (@(x,y) array2str(x,y), {1.1, 4}, {3.1, 6}, "ErrorHandler", @arrayfunerror); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
265 %! B = isfield (A(1), "message") && isfield (A(1), "index"); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
266 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
267 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
268 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
269 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
270 %! assert ([A(1).index, A(2).index], [1, 2]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
271 %!test %% Overwriting setting of "UniformOutput" true |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
272 %! A = arrayfun (@(x,y) array2str(x,y), {1.1, 4}, {3.1, 6}, \ |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
273 %! "UniformOutput", true, "ErrorHandler", @arrayfunerror); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
274 %! B = isfield (A(1), "message") && isfield (A(1), "index"); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
275 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
276 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
277 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
278 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
279 %! assert ([A(1).index, A(2).index], [1, 2]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
280 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
281 %% Input arguments can be of type character or strings |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
282 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
283 %! A = arrayfun (@(x,y) x>y, ["ad", "c", "ghi"], ["cc", "d", "fgh"]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
284 %! assert (A, [false, true, false, true, true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
285 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
286 %! A = arrayfun (@(x,y) x>y, ["a"; "f"], ["c"; "d"], "UniformOutput", true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
287 %! assert (A, [false; true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
288 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
289 %! A = arrayfun (@(x,y) x:y, ["a", "d"], ["c", "f"], "UniformOutput", false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
290 %! assert (A, {"abc", "def"}); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
291 %! %#!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
292 %! A = arrayfun (@(x,y) cell2str(x,y), ["a", "d"], ["c", "f"], "ErrorHandler", @arrayfunerror); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
293 %! B = isfield (A(1), "identifier") && isfield (A(1), "message") && isfield (A(1), "index"); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
294 %! assert (B, true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
295 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
296 %% Input arguments can be of type structure |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
297 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
298 %! a = struct ("a", 1.1, "b", 4.2); b = struct ("a", 3.1, "b", 2); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
299 %! A = arrayfun (@(x,y) (x.a < y.a) && (x.b > y.b), a, b); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
300 %! assert (A, true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
301 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
302 %! a = struct ("a", 1.1, "b", 4.2); b = struct ("a", 3.1, "b", 2); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
303 %! A = arrayfun (@(x,y) (x.a < y.a) && (x.b > y.b), a, b, "UniformOutput", true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
304 %! assert (A, true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
305 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
306 %! a = struct ("a", 1.1, "b", 4.2); b = struct ("a", 3.1, "b", 2); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
307 %! A = arrayfun (@(x,y) x.a:y.a, a, b, "UniformOutput", false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
308 %! assert (isequal (A, {[1.1, 2.1, 3.1]})); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
309 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
310 %! A = arrayfun (@(x) mat2str(x), "a", "ErrorHandler", @arrayfunerror); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
311 %! assert (isfield (A, "identifier"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
312 %! assert (isfield (A, "message"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
313 %! assert (isfield (A, "index"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
314 %! assert (isempty (A.message), false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
315 %! assert (A.index, 1); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
316 %!test %% Overwriting setting of "UniformOutput" true |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
317 %! A = arrayfun (@(x) mat2str(x), "a", "UniformOutput", true, \ |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
318 %! "ErrorHandler", @arrayfunerror); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
319 %! assert (isfield (A, "identifier"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
320 %! assert (isfield (A, "message"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
321 %! assert (isfield (A, "index"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
322 %! assert (isempty (A.message), false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
323 %! assert (A.index, 1); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
324 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
325 %% Input arguments can be of type cell array |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
326 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
327 %! A = arrayfun (@(x,y) x{1} < y{1}, {1.1, 4.2}, {3.1, 2}); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
328 %! assert (A, [true, false]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
329 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
330 %! A = arrayfun (@(x,y) x{1} < y{1}, {1.1; 4.2}, {3.1; 2}, "UniformOutput", true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
331 %! assert (A, [true; false]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
332 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
333 %! A = arrayfun (@(x,y) x{1} < y{1}, {1.1, 4.2}, {3.1, 2}, "UniformOutput", false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
334 %! assert (A, {true, false}); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
335 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
336 %! A = arrayfun (@(x,y) num2str(x,y), {1.1, 4.2}, {3.1, 2}, "ErrorHandler", @arrayfunerror); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
337 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
338 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
339 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
340 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
341 %! assert ([A(1).index, A(2).index], [1, 2]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
342 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
343 %! A = arrayfun (@(x,y) num2str(x,y), {1.1, 4.2}, {3.1, 2}, \ |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
344 %! "UniformOutput", true, "ErrorHandler", @arrayfunerror); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
345 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
346 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
347 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
348 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
349 %! assert ([A(1).index, A(2).index], [1, 2]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
350 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
351 ## Local Variables: *** |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
352 ## mode: octave *** |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
353 ## End: *** |