subsasgn

Assigns a value to an element of a cell or matrix.

Syntax

R = subsasgn(target,subscript,value)

Inputs

target
Type: double | cell
Dimension: scalar | vector | matrix
subscript
Must be a struct with members type and subs. Type must be '()' for matrix assignment or '{}' for cell assignment. Subs is a cell array containing the actual subscripts to be used for the assignment.
Type: struct
Dimension: scalar

Outputs

R
A modified copy of target with the subscript assignment performed. Target is not changed.

Examples

Simple subsasgn example:
val = ones(2,2);
subs.type = '()';
subs.subs = {2,1};
R = subsasgn(val, subs, 0)
R = [Matrix] 2 x 2
  1  1
  0  1
Simple subsasgn example:
val = {1, 'hello', [1,2;3,4]};
subs.type = '{}';
subs.subs = {1,3};
R = subsasgn(val, subs, 'goodbye')
R =
{
[1,1] 1
[1,2] hello
[1,3] goodbye
}