필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How do I make this loop faster?

조회 수: 1 (최근 30일)
jakobjakob
jakobjakob 2018년 6월 9일
마감: Jan 2018년 6월 9일
for j= 1:240
k=index_aanname(j);
for l=1:length(alldata);
while ((strcmp(alldata(l,3), SA{j})) && ...
((TA(1,j) - alldata{l,1}) <= 10.0) && ...
(strcmp(alldata(l,4), 'Voor'))) == 1
B(l) = (tijdnum(l));
end
end
end
How do I make this loop faster? It is during way too long...
  댓글 수: 2
dpb
dpb 2018년 6월 9일
More than likely don't need to loop over l at all but as written B will contain results for those values of l that are anywhere in the combination of the SA/TA arrays. Is this the intended result?
Also, as written the test for TA is signed; is that also intended to be one-sided?
Without rest of data arrays nobody here can test/play around with the problem.
As for speed, was B preallocated? As is, will "grow" dynamically which is a speed bottleneck of first order.
Jan
Jan 2018년 6월 9일
Please post all input data such that we can run the code. Currently the posted code is meaningless, because the while loop does not stop: The condition is not modified by the body of the loop.
It is not useful to ask for the acceleration of a not running code. Please edit the question and fix it.

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by