3

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?

1 Answer 1

6

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

[S1,S2,S3,S4,S5,S6] = deal(eye(6));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.