MATLAB Answers

Optimization on for loop and if statement

1 view (last 30 days)
cglr
cglr on 18 Nov 2019
Edited: Jan on 23 Nov 2019
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.

  0 Comments

Sign in to comment.

Answers (1)

Vladimir Sovkov
Vladimir Sovkov on 19 Nov 2019
firstPlace = find ( telArray(i,1) == sortedArray(:,3) ,1 )
replaces your entire "k" loop.

  0 Comments

Sign in to comment.

Sign in to answer this question.