subsasgn
Subscripted assignment
Syntax
Description
A = subsasgn(A,S,B)A(i) = B, A{i} = B, or
          A.i = B when A is an object.
MATLAB® uses the built-in subsasgn function to interpret indexed
        assignment statements:
- A(i) = Bassigns the values of- Binto the elements of- Aspecified by the subscript vector- i.- Bmust have the same number of elements as- ior be a scalar value.
- A(i,j) = Bassigns the values of- Binto the elements of the rectangular submatrix of- Aspecified by the subscript vectors- iand- j.- Bmust have- length(i)rows and- length(j)columns.
- A colon used as a subscript, as in - A(i,:) = Bor- A(:,i) = B, indicates the entire column or row.
- For multidimensional arrays, - A(i,j,k,…) = Bassigns- Bto the specified elements of- A.- Bmust be- length(i)-by-- length(j)-by-- length(k)-… or be shiftable to that size by adding or removing singleton dimensions.
Tip
You can use fixed-point assignment, for example, A(:) = B, to
            cast a value with one numeric type into another numeric type. This subscripted
            assignment statement assigns the value of B into A
            while keeping the numeric type of A. Subscripted assignment works the
            same way for integer data types.
Note
You must call subsasgn with an output argument.
              subsasgn does not modify the object used in the indexing
            operation (the first argument). You must assign the output to obtain a modified
            object.
Examples
Input Arguments
Output Arguments
Extended Capabilities
Version History
Introduced before R2006a
