arrayfun
Apply a function to each element of an array.
📝 Syntax
B = arrayfun(func, A)
B = arrayfun(func, A1, ..., An)
B = arrayfun(..., 'UniformOutput', false)
[B1, ..., Bm] = arrayfun(...)
📥 Input argument
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.
📤 Output argument
B, B1, ..., Bm - outputs of function applied elementwise. Cell array if 'UniformOutput' is false.
📄 Description
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.
💡 Examples
Apply mean to structure field
Return multiple outputs from function
Return variable-sized outputs in a cell array
🔗 See also
🕔 History
1.14.0
initial version
Last updated
Was this helpful?