Navigation

Operators and Keywords

Function List:

C++ API

: structfun (func, S)
: [A, …] = structfun (…)
: structfun (…, "ErrorHandler", errfunc)
: structfun (…, "UniformOutput", val)

Evaluate the function named name on the fields of the structure S. The fields of S are passed to the function func individually.

structfun accepts an arbitrary function func in the form of an inline function, function handle, or the name of a function (in a character string). In the case of a character string argument, the function must accept a single argument named x, and it must return a string value. If the function returns more than one argument, they are returned as separate output variables.

If the parameter "UniformOutput" is set to true (the default), then the function must return a single element which will be concatenated into the return value. If "UniformOutput" is false, the outputs are placed into a structure with the same fieldnames as the input structure.

s.name1 = "John Smith";
s.name2 = "Jill Jones";
structfun (@(x) regexp (x, '(\w+)$', "matches"){1}, s,
           "UniformOutput", false)
⇒
   {
     name1 = Smith
     name2 = Jones
   }

Given the parameter "ErrorHandler", errfunc defines a function to call in case func generates an error. The form of the function is

function […] = errfunc (se, …)

where there is an additional input argument to errfunc relative to func, given by se. This is a structure with the elements "identifier", "message" and "index", giving respectively the error identifier, the error message, and the index into the input arguments of the element that caused the error. For an example on how to use an error handler, see ‘cellfun’.

See also: cellfun, arrayfun, spfun.

Package: octave