Splitting matrix into fixed rows and N columns

1 回表示 (過去 30 日間)
daniele marchese
daniele marchese 2021 年 12 月 16 日
回答済み: daniele marchese 2021 年 12 月 16 日
Hello,
I have a matrix 3900x3. My goal is to rearrange it every 30x3 values in order to gain a resulting matrix of 30x130. I guess it is a simple task but I am pretty new into matlab codes and could not find any tips on the internet. Hope I clearly explained the problem
  2 件のコメント
Yazan
Yazan 2021 年 12 月 16 日
編集済み: Yazan 2021 年 12 月 16 日
A 3900-by-3 matrix contains 11700 elements, but a 30-by-130 matrix has only 3900, so you can't just reshape the former to get to the latter. Explain better how to move from the first matrix to the second.
daniele marchese
daniele marchese 2021 年 12 月 16 日
I need to rearrange the 3900-by-3 [A B C] matrix concatenating it horizontally every 30-by-3 values.
So the resulting matrix will be 30-by [A B C A B C A B C ...] 390.

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

採用された回答

Torsten
Torsten 2021 年 12 月 16 日
編集済み: Torsten 2021 年 12 月 16 日
M_new = M(1:30,:);
For i=2:130
M_new = horzcat(M_new, M(30*(i-1)+1:30*i,:)); % M is your original matrix (3900 x 3)
end

その他の回答 (1 件)

daniele marchese
daniele marchese 2021 年 12 月 16 日
thank you a lot! it worked well.
much appreciated

カテゴリ

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