UNFOLD Left/right-unfold a 3D array. W = UNFOLD(U, DIR) unfolds the 3-dim. tensor U in direction DIR, where DIR is either 'LEFT' or 'RIGHT' (case insensitive). See also MATRICIZE, TENSORIZE, TENSORPROD_TTEMPS.
0001 function W = unfold( U, dir ) 0002 %UNFOLD Left/right-unfold a 3D array. 0003 % W = UNFOLD(U, DIR) unfolds the 3-dim. tensor U in direction DIR, where 0004 % DIR is either 'LEFT' or 'RIGHT' (case insensitive). 0005 % 0006 % See also MATRICIZE, TENSORIZE, TENSORPROD_TTEMPS. 0007 0008 % TTeMPS Toolbox. 0009 % Michael Steinlechner, 2013-2016 0010 % Questions and contact: michael.steinlechner@epfl.ch 0011 % BSD 2-clause license, see LICENSE.txt 0012 0013 d = size(U); 0014 % pad with 1 for the last dim (annoying) 0015 if length(size(U)) == 2 0016 d = [d, 1]; 0017 end 0018 0019 if strcmpi(dir, 'left') 0020 W = reshape( U, [d(1)*d(2), d(3)] ); 0021 elseif strcmpi(dir, 'right') 0022 W = reshape( U, [d(1), d(2)*d(3)] ); 0023 else 0024 error('Unknown direction specified. Choose either LEFT or RIGHT') 0025 end 0026 end