« Earlier2 items total Later »

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

Swap rows of a matrix

M([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.

« Earlier2 items total Later »




Sponsored by

Sole Central

Your one stop shop for Birkenstock and Crocs shoes and sandles.