swapVars(x,y)

Version 1.1.0.0 (1.17 KB) by Sugato
Swap two variables (of same type and size) as tuples (used in Python).
15 Downloads
Updated 12 Aug 2017

View License

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
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.1.0.0

Updated function description.
Updated function description.

1.0.0.0

Updated the documentation.