필터 지우기
필터 지우기

Change a 3D matrix to a stacked 2D matrix

조회 수: 46 (최근 30일)
Amine Ben Ayara
Amine Ben Ayara 2016년 5월 6일
댓글: Azzi Abdelmalek 2016년 5월 6일
I have a matrix of (5*5*14680) dimensions, basically 14680 of five by five matrices, I need to convert this output to a 2D matrix (I believe) so basically all the rows are stacked up, and the new matrix dimension will then be : 73400*5. I tried this out = reshape(permute(in, [1:14680]), [], 5); but the output matrix was did not seem correct, everything was out of order. Any suggestions? Please.

답변 (2개)

Guillaume
Guillaume 2016년 5월 6일
Your permute does not make much sense and implies that there are 14680 dimensions instead of three. Since all the dimensions are listed ordered, it actually does not swap any of them. Here is the way to do it with reshape:
out = reshape(permute(in, [2 1 3]), size(in, 2), [])'
You need to transpose rows and columns before and after the reshape since matlab operates column-wise.
If thinking in terms of reshape and permute hurts your head (it does for me), it is simpler to go through a cell array and plain concatenation. The downside is speed:
out = num2cell(in, [1 2]); %split into cell array keeping dimensions 1 and 2 together
out = vertcat(out{:}) %concatenate all the cells vertically

Azzi Abdelmalek
Azzi Abdelmalek 2016년 5월 6일
out=reshape(permute(a,[2 1 3]),size(a,2),[])'
  댓글 수: 2
Amine Ben Ayara
Amine Ben Ayara 2016년 5월 6일
Azzi, I do not understand what the [2 1 3] are actually specifying? I do not want the order of my rows to change at all from the original matrix. this will not affect my order, right? Thank you
Azzi Abdelmalek
Azzi Abdelmalek 2016년 5월 6일
Look at the final result, not just the intermediate!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by