How to reshape an M x (aN) matrix into a (aM) x (N) matrix in MATLAB?

1 回表示 (過去 30 日間)
Mehmet
Mehmet 2022 年 3 月 28 日
コメント済み: Mehmet 2022 年 3 月 28 日
Hey everyone,
I want to reshape an M x (aN) matrix into a (aM) x (N) matrix in MATLAB without using nested for loops?
An example transformation is given below if a=3. (Each square is given with a size of M x N)

採用された回答

Bruno Luong
Bruno Luong 2022 年 3 月 28 日
編集済み: Bruno Luong 2022 年 3 月 28 日
Use permute
m = 3;
n = 2;
a = 4;
A = reshape(zeros(m,n)+reshape(1:a,[1 1 a]),[m n*a]);
A
A = 3×8
1 1 2 2 3 3 4 4 1 1 2 2 3 3 4 4 1 1 2 2 3 3 4 4
B = reshape(permute(reshape(A,[m n a]),[1 3 2]),[m*a n])
B = 12×2
1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 4 4
  1 件のコメント
Mehmet
Mehmet 2022 年 3 月 28 日
Great solution Bruno! Thank you.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by