Skip to content

getfield

miscellaneous · scripts/miscellaneous/getfield.m

: v = getfield (s, field)
: v = getfield (s, sub1, field1, …)

Return the value found in structure s by following a chain of field names and subscripts.

Each argument after s extends the access path from left to right: a string is a field name, and a cell array is a list of subscripts written in parentheses, so that

getfield (s, {2, 1}, "name", {3})

stands for s(2,1).name(3). Use ":" in a cell array to select a whole dimension.