subsasgn
Subscripted assignment
Syntax
Description
is called for the syntax 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 ofBinto the elements ofAspecified by the subscript vectori.Bmust have the same number of elements asior be a scalar value.A(i,j) = Bassigns the values ofBinto the elements of the rectangular submatrix ofAspecified by the subscript vectorsiandj.Bmust havelength(i)rows andlength(j)columns.A colon used as a subscript, as in
A(i,:) = BorA(:,i) = B, indicates the entire column or row.For multidimensional arrays,
A(i,j,k,…) = BassignsBto the specified elements ofA.Bmust belength(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
