How to use reshape in specific case

Hi all, can anyone help me with reshaping 3D matrix to 2D in way shown below? Lets say I have a 3D matrix A (A = round(rand(3,3,3)*10))
A(:,:,1) =
0 8 7
1 9 4
1 3 5
A(:,:,2) =
7 5 5
10 7 7
8 4 0
A(:,:,3) =
2 7 4
5 8 8
2 4 6
And i want a 2D matrix C C =
0 8 7
1 9 4
1 3 5
7 5 5
10 7 7
8 4 0
2 7 4
5 8 8
2 4 6
Thank you for any input for this problem

 採用された回答

James Tursa
James Tursa 2013 年 5 月 13 日
編集済み: James Tursa 2013 年 5 月 13 日

0 投票

For your specific example,
reshape(permute(A,[1 3 2]),9,3)
Alter the last two dimensions to fit your actual problem. The purpose of the permute in the above expression is to get the 3rd dimension next to the 1st dimension in memory, and then a simple reshape will finish the job.

3 件のコメント

Jan
Jan 2013 年 5 月 14 日
Thank you for your reply. Another liked question. How to do this in reverse? lets say I have a previosly created 2D matrix and I want to create 3D matrix. I am still not quite sure how to use permute.
Jan
Jan 2013 年 5 月 14 日
Never mind spend another 14 minutes to think of it twice. I appreciate yor help.
This worked
C = reshape(permute(B,[2 1]),3,3,3); NewC = permute(C, [2,1,3])
Andrei Bobrov
Andrei Bobrov 2013 年 5 月 14 日
編集済み: Andrei Bobrov 2013 年 5 月 14 日
C = reshape(permute(A,[2 1 3]),3,[])'
A = permute(reshape(C,3,3,[]),[1 3 2])

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

質問済み:

Jan
2013 年 5 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by