0

Possible Duplicates:
How do I do multiple assignment in MATLAB?
Is there anything like deal() for normal MATLAB arrays?

I want to put values of a vector in 2 variables, but it doesn't work.

vec = [2 3];
[m n] = vec;

I expected:

m = 2

n = 3

But I got an error.

It's a syntax problem or I can't do that?

2

2 Answers 2

3

There are many ways to assign values of a vector to different variables, but you cannot do it like that.

Easy way:

vec = [ 2 3 ];
m = vec(1);
n = vec(2);
Sign up to request clarification or add additional context in comments.

Comments

0

Just another variation using an anonymous function.

vec = [2 3];
tuple = @(x) deal(x(1), x(2))
[m n] = tuple(vec)

1 Comment

While this is correct, this is probably way to advanced for the OP. I suspect this is more of a "How do I index into a matrix?" question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.