Clear Filters
Clear Filters

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 view (last 30 days)
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 Comments
Stephen23
Stephen23 on 16 Jul 2022
Edited: Stephen23 on 16 Jul 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.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!