Mercurial > hg > octave-lyh
annotate scripts/general/arrayfun.m @ 11471:994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 09 Jan 2011 16:01:05 -0800 |
parents | a4f482e66b65 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2006, 2007, 2008, 2009 Bill Denney |
9674 | 2 ## Copyright (C) 2009 Jaroslav Hajek |
6422 | 3 ## |
6439 | 4 ## This file is part of Octave. |
6422 | 5 ## |
6439 | 6 ## Octave is free software; you can redistribute it and/or modify it |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
6439 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
6422 | 15 ## |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
6422 | 19 |
20 ## -*- texinfo -*- | |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
21 ## @deftypefn {Function File} {} arrayfun (@var{func}, @var{A}) |
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
22 ## @deftypefnx {Function File} {@var{x} =} arrayfun (@var{func}, @var{A}) |
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
23 ## @deftypefnx {Function File} {@var{x} =} arrayfun (@var{func}, @var{A}, @var{b}, @dots{}) |
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
24 ## @deftypefnx {Function File} {[@var{x}, @var{y}, @dots{}] =} arrayfun (@var{func}, @var{A}, @dots{}) |
8357
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{}, "UniformOutput", @var{val}) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
26 ## @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
|
27 ## |
6439 | 28 ## Execute a function on each element of an array. This is useful for |
29 ## functions that do not accept array arguments. If the function does | |
6422 | 30 ## accept array arguments it is better to call the function directly. |
31 ## | |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
32 ## 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
|
33 ## handle, an inline function or an anonymous function. The input |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
34 ## argument @var{A} can be a logic array, a numeric array, a string |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
35 ## array, a structure array or a cell array. By a call of the function |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
36 ## @command{arrayfun} all elements of @var{A} are passed on to the named |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
37 ## function @var{func} individually. |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
38 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
39 ## 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
|
40 ## 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
|
41 ## 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
|
42 ## argument then all input arguments must have the same sizes, for |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
43 ## example: |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
44 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
45 ## @example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
46 ## @group |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
47 ## 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
|
48 ## @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
|
49 ## @end group |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
50 ## @end example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
51 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
52 ## 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
|
53 ## "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
|
54 ## 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
|
55 ## 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
|
56 ## if that parameter is set to @code{false}, then the outputs are |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
57 ## concatenated in a cell array. For example: |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
58 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
59 ## @example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
60 ## @group |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
61 ## 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
|
62 ## @result{} ans = |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
63 ## @{ |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
64 ## [1,1] = abcd |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
65 ## [1,2] = bcde |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
66 ## [1,3] = cdef |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
67 ## @} |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
68 ## @end group |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
69 ## @end example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
70 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
71 ## 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
|
72 ## must return the number of return values that also are expected, for |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
73 ## example: |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
74 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
75 ## @example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
76 ## @group |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
77 ## [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
|
78 ## @result{} |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
79 ## A = |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
80 ## @{ |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
81 ## [1,1] = 1 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
82 ## [2,1] = [](0x0) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
83 ## @} |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
84 ## B = |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
85 ## @{ |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
86 ## [1,1] = 1 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
87 ## [2,1] = [](0x0) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
88 ## @} |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
89 ## C = |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
90 ## @{ |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
91 ## [1,1] = 10 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
92 ## [2,1] = [](0x0) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
93 ## @} |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
94 ## @end group |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
95 ## @end example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
96 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
97 ## 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
|
98 ## "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
|
99 ## 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
|
100 ## 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
|
101 ## 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
|
102 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
103 ## @example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
104 ## 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
|
105 ## @end example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
106 ## |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
107 ## @noindent |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
108 ## 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
|
109 ## 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
|
110 ## 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
|
111 ## 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
|
112 ## 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
|
113 ## 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
|
114 ## argument of @var{func}, otherwise a real error is thrown. For |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
115 ## example: |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
116 ## |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
117 ## @example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
118 ## @group |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
119 ## 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
|
120 ## arrayfun (@@str2num, [1234], \ |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
121 ## "UniformOutput", false, "ErrorHandler", @@ferr) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
122 ## @result{} ans = |
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 ## [1,1] = MyString |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
125 ## @} |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
126 ## @end group |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
127 ## @end example |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
128 ## |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9788
diff
changeset
|
129 ## @seealso{spfun, cellfun, structfun} |
6422 | 130 ## @end deftypefn |
131 | |
7017 | 132 ## Author: Bill Denney <denney@seas.upenn.edu> |
9674 | 133 ## Rewritten: Jaroslav Hajek <highegg@gmail.com> |
7017 | 134 |
6439 | 135 function varargout = arrayfun (func, varargin) |
6422 | 136 |
137 if (nargin < 2) | |
6439 | 138 print_usage (); |
6422 | 139 endif |
140 | |
9674 | 141 nargs = length (varargin); |
142 | |
143 recognized_opts = {"UniformOutput", "ErrorHandler"}; | |
144 | |
145 while (nargs >= 2) | |
146 maybeopt = varargin{nargs-1}; | |
147 if (ischar (maybeopt) && any (strcmpi (maybeopt, recognized_opts))) | |
148 nargs -= 2; | |
6422 | 149 else |
9674 | 150 break; |
6422 | 151 endif |
152 endwhile | |
153 | |
9674 | 154 args = varargin(1:nargs); |
155 opts = varargin(nargs+1:end); | |
156 | |
157 args = cellfun (@num2cell, args, "UniformOutput", false, | |
158 "ErrorHandler", @arg_class_error); | |
159 | |
9788
e3e5d43d9d4c
fix arrayfun with nargout=0
Jaroslav Hajek <highegg@gmail.com>
parents:
9674
diff
changeset
|
160 [varargout{1:max(1, nargout)}] = cellfun (func, args{:}, opts{:}); |
9674 | 161 |
162 endfunction | |
163 | |
164 function arg_class_error (S, X) | |
165 error ("arrayfun: invalid argument of class %s", class (X)) | |
6422 | 166 endfunction |
167 | |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
168 %% 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
|
169 %!function [z] = arrayfunerror (S, varargin) |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
170 %! z = S; |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
171 %! endfunction |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
172 %% 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
|
173 %% function_handle or an anonymous function |
6422 | 174 %!test |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
175 %! 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
|
176 %!error |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
177 %! 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
|
178 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
179 %! 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
|
180 %! assert (A, [false, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
181 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
182 %! 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
|
183 %! assert (A, [false, true]); |
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 (@(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
|
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 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
191 %% 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
|
192 %#!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
193 %! 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
|
194 %! assert (A, true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
195 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
196 %! 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
|
197 %! 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
|
198 %!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
|
199 %! 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
|
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 %% 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
|
202 %! 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
|
203 %! assert (A, true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
204 %!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
|
205 %! [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
|
206 %! 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
|
207 %! 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
|
208 %! 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
|
209 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
210 %% 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
|
211 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
212 %! 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
|
213 %! assert (A, [false, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
214 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
215 %! 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
|
216 %! assert (A, [false; true]); |
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) 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
|
219 %! 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
|
220 %!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
|
221 %! [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
|
222 %! assert (isequal (A, {true, []; [], true})); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
223 %! assert (isequal (B, {true, []; [], true})); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
224 %! assert (isequal (C, {true, []; [], true})); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
225 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
226 %! 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
|
227 %! assert (isfield (A, "identifier"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
228 %! assert (isfield (A, "message"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
229 %! assert (isfield (A, "index"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
230 %! assert (isempty (A.message), false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
231 %! assert (A.index, 1); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
232 %!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
|
233 %! 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
|
234 %! "UniformOutput", true, "ErrorHandler", @arrayfunerror); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
235 %! assert (isfield (A, "identifier"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
236 %! assert (isfield (A, "message"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
237 %! assert (isfield (A, "index"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
238 %! assert (isempty (A.message), false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
239 %! assert (A.index, 1); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
240 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
241 %% 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
|
242 %!test |
9622 | 243 %! A = arrayfun (@(x,y) x>y, [1.1, 4.2], [3.1, 2+3*i]); |
8357
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
244 %! assert (A, [false, true]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
245 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
246 %! 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
|
247 %! 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
|
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], [3.1, 6], "UniformOutput", false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
250 %! 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
|
251 %! 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
|
252 %!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
|
253 %! [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
|
254 %! 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
|
255 %! 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
|
256 %! 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
|
257 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
258 %! 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
|
259 %! 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
|
260 %! 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
|
261 %! 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
|
262 %! 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
|
263 %! 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
|
264 %! 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
|
265 %!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
|
266 %! 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
|
267 %! "UniformOutput", true, "ErrorHandler", @arrayfunerror); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
268 %! 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
|
269 %! 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
|
270 %! 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
|
271 %! 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
|
272 %! 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
|
273 %! 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
|
274 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
275 %% 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
|
276 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
277 %! 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
|
278 %! 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
|
279 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
280 %! 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
|
281 %! assert (A, [false; true]); |
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, ["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
|
284 %! assert (A, {"abc", "def"}); |
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) 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
|
287 %! 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
|
288 %! assert (B, true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
289 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
290 %% 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
|
291 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
292 %! 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
|
293 %! 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
|
294 %! assert (A, true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
295 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
296 %! 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
|
297 %! 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
|
298 %! assert (A, true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
299 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
300 %! 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
|
301 %! 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
|
302 %! 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
|
303 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
304 %! 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
|
305 %! assert (isfield (A, "identifier"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
306 %! assert (isfield (A, "message"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
307 %! assert (isfield (A, "index"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
308 %! assert (isempty (A.message), false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
309 %! assert (A.index, 1); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
310 %!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
|
311 %! 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
|
312 %! "ErrorHandler", @arrayfunerror); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
313 %! assert (isfield (A, "identifier"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
314 %! assert (isfield (A, "message"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
315 %! assert (isfield (A, "index"), true); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
316 %! assert (isempty (A.message), false); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
317 %! assert (A.index, 1); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
318 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
319 %% 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
|
320 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
321 %! 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
|
322 %! assert (A, [true, false]); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
323 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
324 %! 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
|
325 %! assert (A, [true; false]); |
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}, "UniformOutput", false); |
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) 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
|
331 %! 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
|
332 %! 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
|
333 %! 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
|
334 %! 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
|
335 %! 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
|
336 %!test |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
337 %! 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
|
338 %! "UniformOutput", true, "ErrorHandler", @arrayfunerror); |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
339 %! 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
|
340 %! 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
|
341 %! 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
|
342 %! 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
|
343 %! 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
|
344 |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
345 ## Local Variables: *** |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
346 ## mode: octave *** |
bdb0a5aea9f2
Minor bug fixes, update help text and tests
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
7017
diff
changeset
|
347 ## End: *** |