Store every N columns in a Matrix to a new Matrix

4 visualizaciones (últimos 30 días)
Ben Whitby
Ben Whitby el 11 de Mayo de 2022
Editada: Ben Whitby el 8 de Jun. de 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

Respuesta aceptada

James Tursa
James Tursa el 11 de Mayo de 2022
Editada: James Tursa el 12 de Mayo de 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 comentario
Ben Whitby
Ben Whitby el 17 de Mayo de 2022
Thanks, with some adjsutments to my original code this does work. The link to the documentation was also useful

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by