Function Reference
— Built-in Function: subsasgn (val, idx, rhs)

Perform the subscripted assignment operation according to the subscript specified by idx.

The subscript idx is expected to be a structure array with fields ‘type’ and ‘subs’. Valid values for ‘type’ are ‘"()"’, ‘"{}"’, and ‘"."’. The ‘subs’ field may be either ‘":"’ or a cell array of index values.

The following example shows how to set the two first columns of a 3-by-3 matrix to zero.

          val = magic(3);
          idx.type = "()";
          idx.subs = {":", 1:2};
          subsasgn (val, idx, 0)
               [ 0   0   6
                   0   0   7
                   0   0   2 ]

Note that this is the same as writing val(:,1:2) = 0.

See also: subsref substruct