Reputation: 579
I am new in Matlab. In Python one can swap elements in a handy way.
x, y = 5, 10
x, y = y, x
Is there something similar in Matlab (or in Octave/Scilab)? Otherwise, what is the best way to swap elements without the use of a temp variable?
Upvotes: 4
Views: 182
Reputation: 19689
deal
is the function that you're looking for.
[y,x] = deal(x,y);
Example:
x=5; y=10;
[y,x] = deal(x,y)
y =
5
x =
10
Upvotes: 5