First, your named examples work with octave, but not with matlab!
octave:1> a=b=c=42
a = 42
octave:2> [a,b,c] = {1,2,3}{:}
a = 1
b = 2
c = 3
>> a=b=c=42
a=b=c=42
|
Error: The expression to the left of the equals sign is not a valid target for an assignment.
>> [a,b,c] = {1,2,3}{:}
[a,b,c] = {1,2,3}{:}
|
Error: Unbalanced or unexpected parenthesis or bracket.
How and when to use deal()
can not be generalized. It depends on you scripte, your datastructure, what you want to do and how the result should look like etc.
>> m=rand(3,3);
>> [a,b,c]=m;
Too many output arguments.
>> [a,b,c]=reshape(m,[],1);
Error using reshape
Too many output arguments.
>> [a,b,c]=deal(reshape(m,[],1));
>>
So some functions are designed with nargout = 1 and you can easily distribute the output to sevaral variables in "one line".
And if a functions has more nargouts than 1, it gets interesting
>> [x,y,z]=qr(m)
x =
-0.7004 0.6471 -0.3012
-0.1144 -0.5183 -0.8475
-0.7045 -0.5592 0.4370
y =
-1.3776 -0.7928 -1.2897
0 -0.6388 -0.0796
0 0 -0.3499
z =
1 0 0
0 0 1
0 1 0
>> [x,y,z]=deal(qr(m))
x =
-1.3776 -1.2897 -0.7928
0.0673 -0.3588 -0.1418
0.4143 -0.1886 0.6229
y =
-1.3776 -1.2897 -0.7928
0.0673 -0.3588 -0.1418
0.4143 -0.1886 0.6229
z =
-1.3776 -1.2897 -0.7928
0.0673 -0.3588 -0.1418
0.4143 -0.1886 0.6229
>>
However, doublicating variables (e.g. to keep a better overview) is not so bad as it might be in other languages (in regard of memory wasting). Matlab uses copy on write - see https://en.wikipedia.org/wiki/Copy-on-write and http://www.matlabtips.com/copy-on-write/
And - afaik - octave too:
octave:1> memory
Memory used by Octave: 24.4414 MB
Physical Memory (RAM): 7586.74 MB
octave:2> tic, m=rand(10000,10000); toc
Elapsed time is 5.52749 seconds.
octave:3> memory
Memory used by Octave: 787.531 MB
Physical Memory (RAM): 7586.74 MB
octave:4> tic, n=m; toc
Elapsed time is 4.19617e-05 seconds.
octave:5> memory
Memory used by Octave: 787.535 MB
Physical Memory (RAM): 7586.74 MB
octave:6> whos
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
m 10000x10000 800000000 double
n 10000x10000 800000000 double
Total is 200000000 elements using 1600000000 bytes