Main Content

substruct

Create structure argument for subsasgn or subsref

Syntax

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

Description

S = substruct(type1, subs1, type2, subs2, ...) creates a structure with the fields required by an overloaded subsref or subsasgn method. Each type char vector must be one of '.', '()', or '{}'. The corresponding subs argument must be either a field name (for the '.' type) or a cell array containing the index vectors (for the '()' or '{}' types).

Output Arguments

S

struct with these fields:

  • type: one of '.', '()', or '{}'

  • subs: subscript values (field name or cell array of index vectors)

Examples

Call subsref with arguments equivalent to the syntax:

B = A(3,5).field;

where A is an object of a class that implements a subsref method

Use substruct to form the input struct, S:

S = substruct('()',{3,5},'.','field');

Call the class method:

B = subsref(A,S);

The struct created by substruct in this example contains:

disp(S(1))
    type: '()'
    subs: {[3]  [5]}

disp(S(2))
    type: '.'
    subs: 'field'

Extended Capabilities

Version History

Introduced before R2006a