loop and array for sum

조회 수: 11 (최근 30일)
Irem Kuzgunkaya
Irem Kuzgunkaya 2020년 5월 12일
댓글: Irem Kuzgunkaya 2020년 5월 12일
magnitude= abs(y); % amplitude of y signal
near= ceil(N/F);
signal= zeros(1,near);
for i=1:1000:N
for j=i:1:near
s = sum(magnitude(i:i+1000));
signal(j)= s;
end
end
I am trying to store every sum in array but instead, i get same result for every signal(j). I think i am missing something.

답변 (2개)

Steven Lord
Steven Lord 2020년 5월 12일
The expression you use to calculate s doesn't depend on j and also doesn't depend on anything that changes inside the loop over j. So it's expected that you receive the same answer each time.
I don't know how you want to modify your code so that the expression you use to calculate s has some dependence on j. If you post the mathematical expression you're trying to compute or the problem you're trying to solve as a comment we may be able to offer some guidance.
  댓글 수: 1
Irem Kuzgunkaya
Irem Kuzgunkaya 2020년 5월 12일
i have a 232 second long signal with N=1000. I want to sum magnitude of every 1000 sample and put every sum in the signal array.

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


drummer
drummer 2020년 5월 12일
s = s + sum(magnitude(i:i+1000));
would it work?
  댓글 수: 1
Irem Kuzgunkaya
Irem Kuzgunkaya 2020년 5월 12일
i tried it but it doesn't.

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

카테고리

Help CenterFile Exchange에서 Signal Operations에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by