MATLAB Answers

Replace loop with more efficient procedure to make it faster

조회 수: 2(최근 30일)
Lukas Netzer
Lukas Netzer 2021년 8월 19일
댓글: Peter Perkins 2021년 9월 2일
So I'm running this loop:
for n = 1:size(table1)
for m = 1:size(table2)
if table1.WP1(n) == table2.WP1(m) && table1.WP2(n) == table2.WP2(m)
table2.STOPS(n) = table2.STOPS(m);
Which takes really long to process - is there a faster way to do it?

채택된 답변

Fangjun Jiang
Fangjun Jiang 2021년 8월 19일
Would this give you a clue?
  댓글 수: 9
Peter Perkins
Peter Perkins 2021년 9월 2일
The double loop is unlikely to be faster for any case. If there is at most one match in table2 for each row of table1, then perhaps ismember would work. But unless these tables are pretty big, the "row == col" strategy is likely to be the fastest.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by