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);
end
end
end
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?
t1=1:3;
t2=(1:4)';
flag=(t1==t2)
  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 件)

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by