Home > GLMdenoise > utilities > reshape2D.m

reshape2D

PURPOSE ^

function f = reshape2D(m,dim)

SYNOPSIS ^

function f = reshape2D(m,dim)

DESCRIPTION ^

 function f = reshape2D(m,dim)

 <m> is a matrix
 <dim> is a dimension of <m>

 shift dimension <dim> to the beginning,
 then reshape to be a 2D matrix.
 see also reshape2D_undo.m.

 example:
 a = randn(3,4,5);
 b = reshape2D(a,2);
 isequal(size(b),[4 15])

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function f = reshape2D(m,dim)
0002 
0003 % function f = reshape2D(m,dim)
0004 %
0005 % <m> is a matrix
0006 % <dim> is a dimension of <m>
0007 %
0008 % shift dimension <dim> to the beginning,
0009 % then reshape to be a 2D matrix.
0010 % see also reshape2D_undo.m.
0011 %
0012 % example:
0013 % a = randn(3,4,5);
0014 % b = reshape2D(a,2);
0015 % isequal(size(b),[4 15])
0016 
0017 % what is the new permutation order? (be careful that <dim> might be larger than number of dimensions of <m>!)
0018 dimorder = [dim setdiff(1:max(ndims(m),dim),dim)];
0019 
0020 % permute and then squish into a 2D matrix
0021 f = reshape(permute(m,dimorder),size(m,dim),[]);

Generated on Fri 01-Aug-2014 12:03:17 by m2html © 2005