Optimize an if loop
Show older comments
Good night people,
I have a question regarding the optimization of the following loop:
for i=1:length(PV)
if i>3
if NL(i-1)<=100
if NL(i-2)<=100
if NL(i-3)<=100
u(i)=1;
else
u(i)=0;
end
end
end
end
end
I would like to reduce the if statements.
Thanks for your time,
Accepted Answer
More Answers (1)
u=[0,0,0, conv(double(NL(:).'<=100),[1,1,1],'valid')>=3];
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!