ASSIGN Making assignments
Section: Array Generation and Manipulations
Usage
FreeMat assignments take a number of different forms, depending on the type of the variable you want to make an assignment to. For numerical arrays and strings, the form of an assignment is eithera(ndx) = val
where ndx
is a set of vector indexing coordinates. This means
that the values ndx
takes reference the elements of a
in column
order. So, if, for example a
is an N x M
matrix, the first column
has vector indices 1,2,...,N
, and the second column has indices
N+1,N+2,...,2N
, and so on. Alternately, you can use multi-dimensional
indexing to make an assignment:
a(ndx_1,ndx_2,..,ndx_m) = val
where each indexing expression ndx_i
corresponds to the i-th
dimension
of a
. In both cases, (vector or multi-dimensional indexing), the
right hand side val
must either be a scalar, an empty matrix, or of the
same size as the indices. If val
is an empty matrix, the assignment acts
like a delete. Note that the type of a
may be modified by the assignment.
So, for example, assigning a double
value to an element of a float
array a
will cause the array a
to become double
.
For cell arrays, the above forms of assignment will still work, but only
if val
is also a cell array. If you want to assign the contents of
a cell in a cell array, you must use one of the two following forms, either
a{ndx} = val
or
a{ndx_1,ndx_2,...,ndx_m} = val
which will modify the contents of the cell.