MATLAB Function Reference    
getfield

Get field of structure array

Syntax

Description

f = getfield(s,'field'), where s is a 1-by-1 structure, returns the contents of the specified field. This is equivalent to the syntax f = s.field.

If s is a structure having dimensions greater than 1-by-1, getfield returns the first of all output values requested in the call. That is, for structure array s(m,n), getfield returns f = s(1,1).field.

f = getfield(s,{i,j},'field',{k}) returns the contents of the specified field. This is equivalent to the syntax f = s(i,j).field(k). All subscripts must be passed as cell arrays--that is, they must be enclosed in curly braces (similar to{i,j} and {k} above). Pass field references as strings.

Examples

Given the structure:

Then the command f = getfield(mystr,{2,1},'name') yields

To list the contents of all name (or other) fields, embed getfield in a loop:

See Also

setfield, rmfield, fieldnames


 getenv getframe