getfield

Extract a field value from a structure s.

Syntax

R = getfield(s,field)

R = getfield(s,field,idx)

Inputs

s
Struct.
Type: struct
Dimension: scalar
field
Name of field.
Type: char | string | logical | struct | cell
Dimension: string
idx
Index (or indices) into struct array. Must be stored in a cell array.
Type: cell

Outputs

R
Content of the specified field.

Example

Simple getfield example:
a = struct('name', 'Bob', 'age', 33);
R = getfield(a, 'age')
R = 33
Simple getfield example:
a = struct('name', {'Bob', 'Dave'}, 'age', {33, 44});
R = getfield(a, {2}, 'age')
R = 44