MATLAB Answers

0

Is this for-loop vectorizable?

Asked by Homo Sapiens on 24 Sep 2019
Latest activity Answered by Bruno Luong
on 24 Sep 2019
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?

  0 Comments

Sign in to comment.

Products


Release

R2019b

1 Answer

Answer by Bruno Luong
on 24 Sep 2019

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

  0 Comments

Sign in to comment.