필터 지우기
필터 지우기

Change the dimension of an output matrix

조회 수: 5 (최근 30일)
Amine Ben Ayara
Amine Ben Ayara 2016년 4월 11일
댓글: Jan 2016년 4월 17일
I have an output matrix of (5*5*44040) dimension. I would like to convert it into 1 dimension so basically all the (5*5) are stacked up and the final matrix is 220200 row. Any ideas? Thank you guys.

답변 (2개)

Jan
Jan 2016년 4월 11일
편집: Jan 2016년 4월 17일
I guess, that you either want a simple:
out = in(:);
Or:
out = reshape(permute(in, [2,1,3]), [], 1);
It depends on what "all the (5*5) are stacked up" exactly means.
  댓글 수: 2
Amine Ben Ayara
Amine Ben Ayara 2016년 4월 12일
Good morning Jan, Thank you for the reply. The matrix that I currently have is ( 5x5x44040), so I basically have 44040 matrices of five by five dimensions. I want them imported to excel as they are, so that's why I thought of stacking all these matrices in order to fit an excel sheet format (220200 rows total).
Jan
Jan 2016년 4월 17일
@Amine Ben Ayara: So please give a meaningful example. You can "stack" the 5x5 blocks row-wise or columns-wise. I've posted code for both versions. Does one of them work as you want? If not, please post an example with a shortwer 2x2x3 matrix.

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


Stephen23
Stephen23 2016년 4월 11일
편집: Stephen23 2016년 4월 12일
You can use permute and reshape:
>> inp(:,:,3) = [0,1;2,3]; % page 3
>> inp(:,:,2) = [4,5;6,7]; % page 2
>> inp(:,:,1) = [8,9;Inf,NaN] % page 1
inp(:,:,1) =
8 9
Inf NaN
inp(:,:,2) =
4 5
6 7
inp(:,:,3) =
0 1
2 3
>> out = reshape(permute(inp,[1,3,2]),[],2)
out =
8 9 % page 1
Inf NaN % page 1
4 5 % page 2
6 7 % page 2
0 1 % page 3
2 3 % page 3
  댓글 수: 2
Amine Ben Ayara
Amine Ben Ayara 2016년 4월 11일
Stephen, in the example you used, the 3 matrices are (2*2), and I see that you have the final ouptut (out) in the order you wanted[1,3,2]; in my case I have 14680 of (5*5) matrices. They are stored in a 3D matrix output, how do I have to modify what you wrote to get one matrix of stacked up row? Thanks
Stephen23
Stephen23 2016년 4월 11일
편집: Stephen23 2016년 4월 11일
@Amine Ben Ayara: note that the output order is actually 1,2,3,4,..., because I presumed that you wanted your matrices arranged sequentially like this. The values [1,3,2] are just used to rearrange the array dimensions, not the output order. (notice that your array has three dimensions, and my array has three dimensions, and these are what are rearranged). In any case, you would only need to change the final reshape size, like this:
reshape(permute(inp,[1,3,2]),[],5)
^ to match the matrix size

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

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by