Borrar filtros
Borrar filtros

As I'm loading data into a cell array through a loop, I end up with a matrix that is double the size of what it should be.

1 visualización (últimos 30 días)
I am loading data into graph1 cell array with two loops. The S matrix is 1x410, but after I run the code, graph1 ends up being 1x820, and the data in the later half of the matrix 411:820 is mostly of zeros. Am I doing something wrong, or can I just ignore the later half? Thanks in advance!
Here is my code:
for i=1:size(tph,1)
strt = floor(tph(i,1)*fs);
lst = floor(tph(i,2)*fs);
filt = chronux.ct.rmlinesmovingwinc(X(strt:lst,channel), [win/fs,step/fs], 20, params, .3, 'n', [59 60 100 119 120 121 140 180]);
[S,f] = chronux.ct.mtspectrumc(filt,params);
for j=1:size(S,1)
graph1{j}(i) = S(j);
end
end
  2 comentarios
Stephen23
Stephen23 el 16 de Jul. de 2022
Editada: Stephen23 el 16 de Jul. de 2022
@Selena: do you preallocate GRAPH1 before the loop? Are the sizes of S the same on every i iteration?
"graph1 ends up being 1x820, and the data in the later half of the matrix 411:820 is mostly of zeros."
This explanation does not match your code, which indicates that GRAPH1 is a cell array or table or similar.
Selena
Selena el 16 de Jul. de 2022
Ooooh I see, S is not the same size every iteration. Thank you for your help!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by