1.tenmat函数:
tenmat Store tensor as a matrix.
tenmat函数将张量存储为矩阵形式,也就是张量展开成矩阵。
2.解析
a为3*4*5的张量
tenmat(a,1)将张量存储为3*[4*5]的矩阵格式。
tenmat(a,2)将张量存储为4*[3*5]的矩阵格式。
tenmat(a,3)将张量存储为5*[3*4]的矩阵格式。
3.例子
>>a=tensor(rand(12,1),[3,2,2])%随机生成一个3*2*2的张量
a is a tensor of size 3 x 2 x 2
a(:,:,1) =
0.6105 0.3864
0.9049 0.7484
0.2277 0.8922
a(:,:,2) =
0.4098 0.0444
0.4421 0.1464
0.7441 0.9583
>> tenmat(a,1)
ans is a matrix corresponding to a tensor of size 3 x 2 x 2
ans.rindices = [ 1 ] (modes of tensor corresponding to rows)
ans.cindices = [ 2 3 ] (modes of tensor corresponding to columns)
ans.data =
0.6105 0.3864 0.4098 0.0444
0.9049 0.7484 0.4421 0.1464
0.2277 0.8922 0.7441 0.9583
令a(:,:,1)=a1, a(:,:,2)=a2, 则函数tenmat(a,1)将张量a表示为[a1,a2].