subsref

Extract a subset of a collection given an indexing method and range. sub on the value val.

Syntax

subsref(val, sub)

Inputs

val
Any valid number.
Type: double | integer | char | string | logical | struct | cell
Dimension: scalar | string | vector | matrix
sub
Type: struct
Dimension: scalar
A struct containing the fields type and subs. The value of type must be '()' or '{}'. The value of subs is a cell array indicating the corresponding ranges to be extracted. The cell contents can either be a scalar, matrix, or the string ':'.

Outputs

R
Resulting scalar | vector | matrix

Example

Simple subsref example.

val = [1 2 3; 4 5 6]
idx.type = '()';
idx.subs = {':', 1:2};
subsref (val, idx)
val = [Matrix] 2 x 3
1 2 3 
4 5 6 
ans = [Matrix] 2 x 2
1 2 
4 5