structfun
Apply a function to each field of a scalar structure.
📝Syntax
B = structfun(fun, S)
B = structfun(fun, S, 'UniformOutput', tf)
📥Input Arguments
Parameter Description
fun function handle applied to each field value.
S scalar structure.
tf 'UniformOutput' flag: true (default) or false.
📤Output Arguments
Parameter Description
B column vector (uniform output) or structure (non-uniform output).
📄Description

structfun(fun, S) applies fun to each field of the scalar structure S and returns the results as a column vector.

With 'UniformOutput' set to false, the results are returned in a structure with the same fields as S.

💡Examples
s.a = 1; s.b = 2; s.c = 3;
structfun(@(x) x * 2, s)
🔗See Also
cellfunarrayfun
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub