for loop for signal with changing conditions?

조회 수: 2 (최근 30일)
Mirko Tomic
Mirko Tomic 2022년 7월 27일
답변: Jan 2022년 7월 27일
Hello, i need to create a for loop for the following orange signal with the first 2 negative peaks then 2 positive and so on
the problem is the for loop should only process the negative ones and not the positive peaks, and i really need a loop here with an if statement and cannot work with diff, find functions etc. because i want to extract specific values only in the negative peaks
my code so far, but i still get the values for the whole signal
for i=length(MomentRechts)%orange signal
if MomentRechts(i)<0;
MomR = find(diff(MomentRechts)>1000);
..
..
..
end
end
Thanks for everykind of help :)

답변 (1개)

Jan
Jan 2022년 7월 27일
Do you mean:
for i = 1:length(MomentRechts)
% Instead of:
for i´= length(MomentRechts)
This command processes the complete signal:
MomR = find(diff(MomentRechts)>1000);
Maybe you want:
if MomentRechts(i) < 0
index = find(MomentRechts(i:end) >= 0, 1);
MomR = find(diff(MomentRechts(i:index)) > 1000);
But then you process this for each negative element again. This does not look useful.
Find the negative parts at first. Then process them block by block, not element by element.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by