答案 0 :(得分:5)
reshape(permute(A,[3 2 1]),size(A,3),[])
示例运行 -
>> A
A(:,:,1) =
7 1 7 5
3 4 8 5
9 4 2 6
A(:,:,2) =
7 7 2 4
7 6 5 6
3 2 9 3
A(:,:,3) =
7 7 5 3
3 9 2 8
5 9 2 3
>> reshape(permute(A,[3 2 1]),size(A,3),[])
ans =
7 1 7 5 3 4 8 5 9 4 2 6
7 7 2 4 7 6 5 6 3 2 9 3
7 7 5 3 3 9 2 8 5 9 2 3
答案 1 :(得分:2)
如果你不介意一点索引疯狂......
您可以使用linear index构建appropriate shape,应用于原始数组会产生所需的结果:
B = A(bsxfun(@plus, (1:L*M:L*M*N).', reshape(bsxfun(@plus, (0:L:L*M-1).', 0:L-1),1,[])));
示例:
>> A = randi(10,2,3,4)-1; %// example array; size 2x3x4
>> A
A(:,:,1) =
5 3 2
9 8 9
A(:,:,2) =
8 7 4
9 8 6
A(:,:,3) =
3 4 8
0 4 4
A(:,:,4) =
2 8 8
4 6 7
结果:
>> B
B =
5 3 2 9 8 9
8 7 4 9 8 6
3 4 8 0 4 4
2 8 8 4 6 7
答案 2 :(得分:1)
使用MATLABs矩阵展开语法很容易做到:
A=ones(N,M,O);
B=zeros(O,N*M);
for ii=1:size(A,3)
aux=A(:,:,ii); % aux is NxM
B(ii,:)=aux(:); % unroll!
end
(请注意,我在照片中将O
称为N