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 string 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).

The output S is a structure array containing the fields

Examples

To call subsref with parameters equivalent to the syntax

B = A(3,5).field

you can use

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

The structure created by substruct in this example contains the following:

S(1)

ans = 

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

S(2)

ans = 

    type: '.'
    subs: 'field'

See Also

subsasgn, subsref

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS