Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of sltensor_unfold
Home > sltoolbox > tensor > sltensor_unfold.m

sltensor_unfold

PURPOSE ^

SLTENSOR_UNFOLD Unfolds a tensor to a matrix

SYNOPSIS ^

function M = sltensor_unfold(T, k)

DESCRIPTION ^

SLTENSOR_UNFOLD Unfolds a tensor to a matrix 

 $ Syntax $
   - M = sltensor_unfold(T, k)

 $ Arguments $
   - T:        the tensor
   - k:        the dimension along which the tensor is unfolded
   - M:        the matrix obtained by unfolding the tensor

 $ Description $
   - M = sltensor_unfold(T, k) Unfolds a tensor T to the matrix M along
   the k-th dimension.

 $ History $
   - Created by Dahua Lin on Dec 17th, 2005

CROSS-REFERENCE INFORMATION ^

This function calls:
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
This function is called by:

SOURCE CODE ^

0001 function M = sltensor_unfold(T, k)
0002 %SLTENSOR_UNFOLD Unfolds a tensor to a matrix
0003 %
0004 % $ Syntax $
0005 %   - M = sltensor_unfold(T, k)
0006 %
0007 % $ Arguments $
0008 %   - T:        the tensor
0009 %   - k:        the dimension along which the tensor is unfolded
0010 %   - M:        the matrix obtained by unfolding the tensor
0011 %
0012 % $ Description $
0013 %   - M = sltensor_unfold(T, k) Unfolds a tensor T to the matrix M along
0014 %   the k-th dimension.
0015 %
0016 % $ History $
0017 %   - Created by Dahua Lin on Dec 17th, 2005
0018 %
0019 
0020 %% parse and verify
0021 if nargin < 2
0022     raise_lackinput('sltensor_unfold', 2);
0023 end
0024 
0025 %% compute
0026 n = ndims(T);
0027 if k == 1
0028     M = T(1:end, :);
0029 elseif k <= n
0030     if k < n
0031         pdims = [k, 1:k-1, k+1:n];
0032     else
0033         pdims = [k, 1:k-1];
0034     end
0035     M = permute(T, pdims);
0036     M = M(1:end, :);
0037 else
0038     M = T(:)';
0039 end
0040 
0041 
0042 
0043 
0044 
0045 
0046     
0047

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com