Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I assign a single value/matrix to multiple variables in MATLAB?

I am attempting to assign the 6x6 identity matrix to 21 variables. My code looks like this:

[S1,S2,S3,S4,S5,S6,L21,L31,L41,L51,L61,L32,L42,L52,L62,L43,L53,L63,L54,L64,L65] = eye(6);

I understand why this does not work, but I have not been able to find any way to do this in a single line of code, which I really ought to be able to do.

How would I do this in the least amount of code possible? A similar example would be:

[a,b,c,d] = 5

How can I assign multiple variables to the same value/matrix?

like image 448
Evan Guthrie Avatar asked Jan 24 '26 23:01

Evan Guthrie


1 Answers

You can assign the same value to many variables using deal:

[S1,S2,S3,S4,S5,S6] = deal(eye(6));
like image 172
Cris Luengo Avatar answered Jan 26 '26 16:01

Cris Luengo