B = arrayfun(func, A)
B = arrayfun(func, A1, ..., An)
B = arrayfun(..., 'UniformOutput', false)
[B1, ..., Bm] = arrayfun(...)
| Parameter | Description |
|---|---|
| func | function handle to apply on each element. Must return scalar unless 'UniformOutput' is false. |
| A, A1, ..., An | input arrays of the same size. |
| 'UniformOutput' | logical scalar. If false, outputs are returned in a cell array. |
| Parameter | Description |
|---|---|
| B, B1, ..., Bm | outputs of function applied elementwise. Cell array if 'UniformOutput' is false. |
arrayfun(func, A) applies the functionfunc to each element of array A, and returns the result inB with the same size as A.
arrayfun(func, A1, ..., An) appliesfunc to corresponding elements of input arrays. All arrays must be the same size.
Use the 'UniformOutput' option set tofalse to allow output values that cannot be concatenated into a single array. In this case, the result is a cell array.
[B1, ..., Bm] = arrayfun(...) captures multiple outputs from the applied function.
S(1).f1 = rand(1, 5);
S(2).f1 = rand(1, 10);
S(3).f1 = rand(1, 15);
means = arrayfun(@(x) mean(x.f1), S);
f = @(x) deal(x, x^2);
[A, B] = arrayfun(f, 1:4);
S(1).f1 = rand(3,5);
S(2).f1 = rand(2,6);
A = arrayfun(@(x) mean(x.f1), S, 'UniformOutput', false);
| Version | Description |
|---|---|
| 1.14.0 | initial version |