Assign values to entries of an array, a list, or a table
MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
[index1] = value1,
[index2] = value2, …) assignElements(
[[index1], value1], [[index2], value2], …)
assignElements(L, [index1] = value1, [index2] = value2,
...) returns a copy of
value2 stored at
the same effect as the sequence of assignments
R[index2]:=value2: ... R, but is more efficient.
assignElements returns a modified copy of
its first argument, which remains unchanged. See Example 1.
The second variant of the
with lists instead of equations, is equivalent to the first variant.
In fact, both equations and lists may be mixed in a single call. See Example 1.
All assignments are performed simultaneously, i.e., the order of the arguments is irrelevant. See Example 3.
All rules for indexed assignments apply,
in particular with respect to the validity of indices. If
a list, the indices must be positive integers not exceeding the length of
L is an array,
the indices must be (sequences of) integers matching the dimension
and lying within the valid ranges of the array. If
a table, the indices may be arbitrary
Assignments may given as equations or lists, and both forms may be mixed in a single call:
L := array(1..3, [3, 4, 5]); assignElements(L,  = one,  = two,  = three); assignElements(L, [, one], [, two], [, three]); assignElements(L,  = one, [, two],  = three);
L itself is not modified by
Sequences, too, may be assigned as values to array elements, but they must be put in parentheses:
R := assignElements(array(1..2),  = (1, 7),  = PI); [R], [R]
The sequence generator
$ is useful to create sequences of assignments:
L := [i $ i = 1..10]; assignElements(L, [i] = L[i] + L[i + 1] $ i = 1..9)
The order of the arguments is irrelevant:
assignElements(L, [10 - i] = L[10 - i] + L[11 - i] $ i = 1..9)
The indices of a table may be arbitrary objects, for example, strings:
assignElements(table(), [expr2text(i)] = i^2 $ i = 1..4)
For arrays of dimension greater than one, the indices are sequences of as many integers as determined by the dimension of the array:
assignElements(array(1..3, 1..3), ([i, j] = i + j $ i = 1..3) $ j = 1..3)
Valid indices for
Any MuPAD® objects
Object of the same type as