SWAP(A,B) puts the contents of variable A into variable B and vice versa. You can use either function syntax 'swap(A,B)' or command syntax 'swap A B'.
Example:
A = 1:4 ; B = 'Hello' ;
swap(A,B) ;
A % -> Hello
B % -> 1 2 3 4
swap A B ; % and back again ...
SWAP(A,B) is a convenient easy short-cut for other (series of) commands that have the same effect,e.g.,
temp=A ; A=B ; B=temp ; clear temp ;
[B,A] = deal(A,B) ;
The advantage over these two methods is that using SWAP one does not have to declare intermediate variables or worry about output.
Cita come
Jos (10584) (2024). SWAP (https://www.mathworks.com/matlabcentral/fileexchange/12239-swap), MATLAB Central File Exchange. Recuperato .
Compatibilità della release di MATLAB
Compatibilità della piattaforma
Windows macOS LinuxCategorie
Tag
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Scopri Live Editor
Crea script con codice, output e testo formattato in un unico documento eseguibile.
Versione | Pubblicato | Note della release | |
---|---|---|---|
1.0.0.0 | 1. Use <deal> to swap (insight from US)
|