Info

此问题已关闭。 请重新打开它进行编辑或回答。

How to convert 3D matrix to 2D with a specific format

1 次查看(过去 30 天)
Hello all :)
I have a [1000,64,10] matrix and want to change it to a [10000,64] in a way that the first 1000 rows in 2D matrix belong to [:,:,1] in 3D matrix and the 2nd 1000 rows to [:,:,2] and so on, in other words I want the element (1001,1) in the new matrix corresponds to (1,1,2) in the old one and (2001,1) corresponds to (1,1,3) and so on.
Is there any function applying this rule?
Thanks :)

回答(2 个)

Azzi Abdelmalek
Azzi Abdelmalek 2014-3-4
A=rand(1000,64,10);
B=permute(A,[ 2 1 3]);
out=B(:,:)'
  5 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2014-3-5
RH, I posted a short example, I think my code is doing what you asked. If not, please, post the expected result from my short example
RH
RH 2014-3-5
Dear Azzi
It does exactly what I was looking for... Thanks again! :)
Chears

Andrei Bobrov
Andrei Bobrov 2014-3-5
编辑:Andrei Bobrov 2014-3-5
A = randi(100,3,4,4);
a1 = num2cell(A,[1 2]);
out = cat(1,a1{:});
or
out = reshape(permute(A,[1 3 2]),[],size(A,2));
  1 个评论
RH
RH 2014-3-5
Dear Andrei
Thanks for the help, I'm going to check it too, it's always handy to know different solutions. :)
Cheers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by