Store every N columns in a Matrix to a new Matrix
4 ビュー (過去 30 日間)
古いコメントを表示
Hi All,
I have a large Matrix, 15 x 688128. I need to iterate through the matrix saving each set of 4096 columns to a new matrix such that I end up with 168 new matrices each 15 x 4096 in size
S1 contains columns 1 to 4096
S2 contains columns 4097 - 8192
etc such that the final matrix contains columns 684032 to 688128.
I have the loop below but this obviously overwrites the matrix on each iteration through the loop so I only end up with one matrix rather than 168 of them...How can I save the matrix on each iteration?
for nn = 0:688128
CorBeam13 = CorBeam1(:,nn*4096+1:(nn+1)*4096); %Take Vales for each ensemble period. Each ensemble period is 17.0667 secs long and contains 4096 samples
end
0 件のコメント
採用された回答
James Tursa
2022 年 5 月 11 日
編集済み: James Tursa
2022 年 5 月 12 日
Don't create a bunch of new matrices with hard to use names downstream in your code. Instead, simply reshape your matrix and then use indexing. E.g.,
CorBeam13 = reshape(CorBeam13,15,4096,[]);
Then downstream in your code, instead of S1, S2, etc., simply use CorBeam13(:,:,1), CorBeam13(:,:,2), etc.
If for some reason you really want them split up, you could convert them to a cell array of matrices with the mat2cell( ) function, which would still allow you to use easy indexing downstream in your code.
See this link:
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!