FUNCTION REFERENCE

setfield

Set a field in a scalar struct.

Set a field in a scalar struct.

Syntax

T = setfield(S, field, value)

Syntax

T = setfield(S, field1, field2, ..., value)

Returns an updated struct without changing S unless assigned back to S. Follows nested scalar fields and creates missing struct fields along the path. Field names must be valid character names. Paths and resulting containers are limited to 16 nesting levels.

Example

s=struct('a',1,'b','x'); t=setfield(s,'a',7); t.a   % 7

Differences from MATLAB: Cell index arguments and nonscalar structs are not supported.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.