4

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?

Dimitris
  • 569
  • 3
  • 14

1 Answers1

5

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
Sardar Usama
  • 19,536
  • 9
  • 36
  • 58