1

I am trying to do something like this in Octave:

Assign some variables to a matrix, do some operation on the matrix and then assign the members of the matrix back to the variables, e.g:

x=1; y=2; d=[x y]; d=(d.^2)+1; [x y]=d; 

However, this does not work and only x is assigned the complete matrix. Is there a way to achieve this?

1 Answer 1

3

You can index into d.

x=d(1); y=d(2); 

or convert d to a cell array using num2cell and then to a comma-separated list and then deal it.

[x, y] = deal(num2cell(d){:}); 

I recommend the first method.

Sign up to request clarification or add additional context in comments.

2 Comments

The second way is what I was looking for (although I don't completely understand it). Thank you!
One-liners are overrated. Anyway, try doing it in parts and see the output for each part. Let me know if you still find anything unclear

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.