Is this for-loop vectorizable?

b=1;
for a=2:length(ToneLines)
if ToneLines(a)-ToneLines(b)>13000
b=a;
else
ToneLines(a)=0;
end
end
ToneLines=ToneLines(ToneLines>0);
ToneLines is a vector of positive integers sorted from small to large without any equal elements. Is it possible to vectorize this loop for a better performance?

Risposte (1)

Bruno Luong
Bruno Luong il 24 Set 2019

0 voti

I don't think sequential search can be vectorizable.
You might improve a bit of the search by implementing dichotomy seach rather than linear.

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Prodotti

Release

R2019b

Richiesto:

il 24 Set 2019

Risposto:

il 24 Set 2019

Community Treasure Hunt

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

Start Hunting!

Translated by