Is this for-loop vectorizable?

1 次查看(过去 30 天)
埃博拉酱
埃博拉酱 2019-9-24
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?

回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by