Optimization on for loop and if statement

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 个)

firstPlace = find ( telArray(i,1) == sortedArray(:,3) ,1 )
replaces your entire "k" loop.

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

提问:

2019-11-18

编辑:

Jan
2019-11-23

Community Treasure Hunt

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

Start Hunting!

Translated by