Effacer les filtres
Effacer les filtres

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 vue (au cours des 30 derniers jours)
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 commentaires
Stephen23
Stephen23 le 16 Juil 2022
Modifié(e) : Stephen23 le 16 Juil 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 le 16 Juil 2022
Ooooh I see, S is not the same size every iteration. Thank you for your help!

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by