for loop for signal with changing conditions?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 :)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1079305/image.png)
0 Kommentare
Antworten (1)
Jan
am 27 Jul. 2022
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!