This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Create structure argument for subsasgn or subsref


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


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


struct with these fields:

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

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


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:

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

    type: '.'
    subs: 'field'

Introduced before R2006a