How to optimize condition code?
4 次查看(过去 30 天)
显示 更早的评论
Hi all,
I have example for check value in for loop as below
for cnt=1:10
if cnt == 1
if a(cnt) == 0
statement A;
else
statement B;
end
else %% if cnt >= 1
if a(cnt) == 0 || a(cnt-1) == 1
statement A;
else
statement B;
end
end
end
You can see that some lines are dupplicate. Do anyone can optimize condition in loop ?
for cnt=1:10
if new_condition ???
statement A;
else
statement B;
end
end
0 个评论
采纳的回答
Chunru
2022-9-14
for cnt=1:10
if (cnt == 1 && a(cnt) == 0) || (cnt>1 && (a(cnt) == 0 || a(cnt-1) == 1))
statement A;
else
statement B;
end
end
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!