for loop for signal with changing conditions?
2 views (last 30 days)
Show older comments
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 :)
0 Comments
Answers (1)
Jan
on 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 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!