필터 지우기
필터 지우기

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 (최근 30일)
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
Stephen23
Stephen23 2022년 7월 16일
편집: Stephen23 2022년 7월 16일
@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 2022년 7월 16일
Ooooh I see, S is not the same size every iteration. Thank you for your help!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by