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,

 채택된 답변

Matt J
Matt J 2020년 11월 8일

0 개 추천

t=double(NL(:).'<=100);
u=(movsum(t,[3,0])-t)>=3;

댓글 수: 1

Ricardo López
Ricardo López 2020년 11월 9일
What should I do if I want to add more conditions, like in my example? And stored them in a u=zero(1,length(PV))
Thank you for your time

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2020년 11월 8일
편집: Matt J 2020년 11월 8일

0 개 추천

u=[0,0,0, conv(double(NL(:).'<=100),[1,1,1],'valid')>=3];

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2020년 11월 8일

댓글:

2020년 11월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by