Reshaping a 2 d matrix into a 3 d matrix row wise.

11 ビュー (過去 30 日間)
Russ
Russ 2020 年 2 月 21 日
コメント済み: Russ 2020 年 2 月 21 日
Hello, and thanks for taking the time to read this:
I have a 100 x 99 matrix of ratings. I would like to reshape the matrix into a 9x11x100 array where the first row represents the first 9 horizsontal items of the first row. Byu way of a smaller example, imagine the data were:
7 6 5 4 5 6
1 5 6 6 6 2
1 6 6 6 6 1
5 5 6 6 7 2
I would like the result to be:
765
456
156
662
556
672
Can anyone please help with this?

採用された回答

the cyclist
the cyclist 2020 年 2 月 21 日
編集済み: the cyclist 2020 年 2 月 21 日
For your small example, if A is your original matrix, then
permute(reshape(A',3,2,[]),[2 1 3])
For the larger one,
permute(reshape(A',9,11,[]),[2 1 3])
  3 件のコメント
the cyclist
the cyclist 2020 年 2 月 21 日
Yes, I see you effectively have these two conflicting statements in your question:
  • result is 9x11x100
  • first row is the first 9 items
These are conflicting because if the result is 9x11x100, then the first row has 11 items.
But it sounds like you got what you needed.
Russ
Russ 2020 年 2 月 21 日
Yep, now I understand where I went wrong. The first row was supposed to be the first 11 items, not the first 9 items. Thanks so much for solving this problem!

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

その他の回答 (1 件)

Daniel Vieira
Daniel Vieira 2020 年 2 月 21 日
A=randi(10,100,99); % example of what your matrix might be
B=permute(reshape(A',9,11,[]),[2 1 3]) % solution
  1 件のコメント
Russ
Russ 2020 年 2 月 21 日
Thanks! The following alternative seemed to do the trick.
permute(reshape(A', 11,9,[]), [2 1 3])
Thanks!
Russ

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by