"Row-wise" reshape of 3d matrix -> 2d matrix

6 ビュー (過去 30 日間)
Oscar Frick
Oscar Frick 2018 年 9 月 7 日
コメント済み: Raymond MacNeil 2020 年 5 月 13 日
I need to do a reshape of a 3d matrix to a 2d matrix, but where first row of each matrix along the 3d dimension corresponds to the first "set" of rows in the finished 2d matrix.
For example, lets say I have a matrix like this:
M(:,:,1) = [
111 121
211 221]
M(:,:,2) = [
112 122
212 222]
M(:,:,3) = [
113 123
213 223]
I want it to be reshaped into
M_Reshaped
111 121
112 122
113 123
211 221
212 222
213 223
I know about
reshape(permute(M,[1 3 2]), [], 3, 1);
But that simply stacks each matrix along the 3d dimension on top of each other, which is not what I want to achieve. I could do it in a loop, but I've got a feeling there's a more elegant and efficient way that I have not managed to figure out.

採用された回答

Guillaume
Guillaume 2018 年 9 月 7 日
You simply need a different permutation of the dimensions:
reshape(permute(M, [3 1 2]), [], size(M, 2))
  2 件のコメント
Oscar Frick
Oscar Frick 2018 年 9 月 7 日
I clearly need a better feeling for how the permute + reshape works, thanks!
Raymond MacNeil
Raymond MacNeil 2020 年 5 月 13 日
Good question, Oscar.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by