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) = B
assigns the values ofB
into the elements ofA
specified by the subscript vectori
.B
must have the same number of elements asi
or be a scalar value.A(i,j) = B
assigns the values ofB
into the elements of the rectangular submatrix ofA
specified by the subscript vectorsi
andj
.B
must havelength(i)
rows andlength(j)
columns.A colon used as a subscript, as in
A(i,:) = B
orA(:,i) = B
, indicates the entire column or row.For multidimensional arrays,
A(i,j,k,…) = B
assignsB
to the specified elements ofA
.B
must 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