substruct

Create structure argument for subsasgn or subsref

Syntax

  • S = substruct(type1, subs1, type2, subs2, ...)

Description

S = substruct(type1, subs1, type2, subs2, ...) generates a structure containing fields necessary for an overloaded subsref or subsasgn method.

Each type char vector is limited to '.', '()', or '{}'.

The associated subs argument should be a field name (for the '.' type) or a cell array containing index vectors (for the '()' or '{}' types).

Example

S = struct('field1', 10, 'field2', 'Hello', 'field3', [1, 2, 3]);
% Create a substruct for accessing the 'field2'
s = substruct('.', 'field2');
% Use subsref to get the value of 'field2'
value = subsref(S, s);

See also

subsref, subsasgn.

History

VersionDescription

1.0.0

initial version

Author

Allan CORNET

Last updated