Swap Function
This snippet is thanks to Loren Shure from her blog. It is a quick way of writing a swap function.swap=@(varargin)varargin{nargin:-1:1};
and can be used as
a = 1; b = 2; c = 17; [a,b,c] = swap(a,b,c)
resulting in
a = 17 b = 2 c = 1
Matlab Snippets > swap >
Post Matlab code snippets. Sort by tags, people, people and tags, etc.. Brought to you by XTargets - Consulting & Application devlopment.
Swap FunctionThis snippet is thanks to Loren Shure from her blog. It is a quick way of writing a swap function.swap=@(varargin)varargin{nargin:-1:1}; and can be used as a = 1; b = 2; c = 17; [a,b,c] = swap(a,b,c) resulting in a = 17 b = 2 c = 1 Swap rows of a matrixM([1,5],:) = M([5,1],:) interchanges rows 1 and 5 of M. More generally, if V has m components and W has n components, then M(V,W) is the m-by-n matrix formed from the elements of M whose subscripts are the elements of V and W.
|
|