Optimization on for loop and if statement

1 回表示 (過去 30 日間)
cglr
cglr 2019 年 11 月 18 日
編集済み: Jan 2019 年 11 月 23 日
Hi,
Is there any alternative way to improve these statements ?
for i = 1:telegramCount
for k = 1:calculationCount
if(telArray(i,1) == sortedArray(k,3))
firstPlace = k;
break;
end
end
end
Thanks in advance.

回答 (1 件)

Vladimir Sovkov
Vladimir Sovkov 2019 年 11 月 19 日
firstPlace = find ( telArray(i,1) == sortedArray(:,3) ,1 )
replaces your entire "k" loop.

カテゴリ

Help Center および File ExchangeQuadratic Programming and Cone Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by