substruct

Builds the index structure expected by subsref and subsasgn.

Category: Programming > Classes

Syntax

S = substruct(type1, subs1, ..., typeN, subsN)

Returns an N-element struct array, one element per indexing level.

Description

substruct only packages the arguments: the result is a struct array whose type and subs fields are the ones subsref and subsasgn read. The call substruct('.', 'a', '()', {2}) describes the chain .a(2).

A colon is written as the text ':' inside the cell, so substruct('()', {':', 1}) stands for (:, 1).

Input arguments

type
One of '()', '{}' or '.'.
subs
For '()' and '{}', a cell array with one entry per dimension (':' for all). For '.', a field name as text.

Output arguments

S
Struct array with fields type and subs.

Example

A two-level chain

S = substruct('.', 'a', '()', {2})
S(1)
S(2)
Output
S = 1×2 struct array with fields:

    type
    subs
ans = struct with fields:

    type: '.'
    subs: 'a'
ans = struct with fields:

    type: '()'
    subs: {[2]}

See also

subsref subsasgn struct numArgumentsFromSubscript