| Contents | Index |
[A1,...,An] = structfun(func,S)
[A1,...,An] = structfun(func,S,Name,Value)
[A1,...,An] = structfun(func,S) applies the function specified by function handle func to each field of scalar structure S. Output arrays A1,...,An, where n is the number of outputs from function func, contain the outputs from the function calls.
[A1,...,An] = structfun(func,S,Name,Value) calls function func with additional options specified by one or more Name,Value pair arguments. Possible values for Name are 'UniformOutput' or 'ErrorHandler'.
Specify optional comma-separated pairs of Name,Value arguments, where Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.
A1,...,An |
Arrays that collect the n outputs from function func.
If UniformOutput is true (the default):
If UniformOutput is false, each array A is a scalar structure with the same fields as input S. |
Create a scalar structure, and count the number of characters in each field.
s.f1 = 'Sunday'; s.f2 = 'Monday'; s.f3 = 'Tuesday'; s.f4 = 'Wednesday'; s.f5 = 'Thursday'; s.f6 = 'Friday'; s.f7 = 'Saturday'; lengths = structfun(@numel, s)
Shorten the text in each field of s, created in the previous example. Because the output is nonscalar, set UniformOutput to false.
shortNames = structfun(@(x) ( x(1:3) ), s, 'UniformOutput', false)
The syntax @(x) creates an anonymous function.
Define and call a custom error handling function.
function result = errorfun(errorinfo, field) warning(errorinfo.identifier, errorinfo.message); result = NaN; end mystruct.f1 = 'text'; myresult = structfun(@(x) x^2, mystruct, 'ErrorHandler', @errorfun)
arrayfun | cell2mat | cellfun | function_handle | spfun

Explore how to use MATLAB to make advancements in engineering and science.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |