Set
Set(expr, value)
expr = value
evaluates
value
and assigns it toexpr
.
{s1, s2, s3} = {v1, v2, v3}
sets multiple symbols
(s1, s2, ...)
to the corresponding values(v1, v2, ...)
.
Examples
Set
can be used to give a symbol a value:
>> a = 33
>> a3
You can set multiple values at once using lists:
>> {a, b, c} = {10, 2, 3}{10,2,3}
>> {a, b, {c, {d}}} = {1, 2, {{c1, c2}, {a}}}{1,2,{{c1,c2},{10}}}
>> d10
Set
evaluates its right-hand side immediately and assigns it to the left-hand side:
>> a1
>> x = a1
>> a = 22
>> x1
‘Set’ always returns the right-hand side, which you can again use in an assignment:
>> a = b = c = 2>> a == b == c == 2True
‘Set’ supports assignments to parts:
>> A = {{1, 2}, {3, 4}}>> A[[1, 2]] = 55
>> A{{1,5}, {3,4}}
>> A[[;;, 2]] = {6, 7}{6,7}
>> A{{1,6},{3,7}}
Set a submatrix:
>> B = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}>> B[[1;;2, 2;;-1]] = {{t, u}, {y, z}}>> B{{1, t, u}, {4, y, z}, {7, 8, 9}}
Related terms
SetDelayed, TagSet, TagSetDelayed
Implementation status
- ✅ - full supported