Store every N columns in a Matrix to a new Matrix

4 vues (au cours des 30 derniers jours)
Ben Whitby
Ben Whitby le 11 Mai 2022
Modifié(e) : Ben Whitby le 8 Juin 2022
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

Réponse acceptée

James Tursa
James Tursa le 11 Mai 2022
Modifié(e) : James Tursa le 12 Mai 2022
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:
  1 commentaire
Ben Whitby
Ben Whitby le 17 Mai 2022
Thanks, with some adjsutments to my original code this does work. The link to the documentation was also useful

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by