swapVars(x,y)
Function Description:
This function swaps the a pair of input variables, provided they are of
the same size (shape).
AUTHOR: Sugato Ray | Created on: 12-AUG-2017 | ray.sugato[at]gmail.com
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PLEASE ACKNOWLEDGE THE AUTHOR IF YOU USE THIS CODE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NOTE: X = y and Y = x. This function enables you to write the following
expression (equivalent to Tuples concept in Python).
[X,Y] = swapVars(X,Y);
EXAMPLE:
[X,Y] = swapVars(X,Y);
Check the following steps for step-by-step clarity and fact-checking:
xx = ones(3,3)
yy = zeros(3,3)
[xx,yy] = swapVars(xx,yy)
Note: This function works similar to: 'deal' function
[yy,xx] = deal(xx,yy)
Cite As
Sugato (2025). swapVars(x,y) (https://in.mathworks.com/matlabcentral/fileexchange/64090-swapvars-x-y), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- MATLAB > External Language Interfaces > Python with MATLAB > Call Python from MATLAB > Python Data Types in MATLAB >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
