Data structures | cell >> |
B = arrayfun(func, A) |
B = arrayfun(func, A1, ..., An) |
B = arrayfun(..., 'UniformOutput', false) |
[B1, ..., Bm] = arrayfun(...) |
function handle to apply on each element. Must return scalar unless 'UniformOutput' is false.
input arrays of the same size.
logical scalar. If false, outputs are returned in a cell array.
outputs of function applied elementwise. Cell array if 'UniformOutput' is false.
arrayfun(func, A) applies the function func to each element of array A, and returns the result in B with the same size as A.
arrayfun(func, A1, ..., An) applies func to corresponding elements of input arrays. All arrays must be the same size.
Use the 'UniformOutput' option set to false 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.
Apply mean to structure field
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);
Return multiple outputs from function
f = @(x) deal(x, x^2);
[A, B] = arrayfun(f, 1:4);
Return variable-sized outputs in a cell array
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 |
Allan CORNET