Borrar filtros
Borrar filtros

Optimization on for loop and if statement

1 visualización (últimos 30 días)
cglr
cglr el 18 de Nov. de 2019
Editada: Jan el 23 de Nov. de 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.

Respuestas (1)

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

Categorías

Más información sobre Problem-Based Optimization Setup en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by