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일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2019년 9월 24일

답변:

2019년 9월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by