for loop for signal with changing conditions?

2 次查看(过去 30 天)
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 中查找有关 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