Efficiently find most recent value using TIME column in two tables

Hi everyone,
I have two large tables (> 10 million rows), one containing measurement data ("data")
  • each data point with a time stamp, approximately 2 Hz but significant jitter
one containing reference data ("ref")
  • also with one time stamp per data point, approximately 1.5 Hz but significant jitter as well
I'd like to add a column to "data" named data.ref which always contains the most recent reference point.
The following works, but is incredibly inefficient:
for k=1:numel(data.TIME)
i_mostRecent = find(ref.TIME <= data.TIME(k), 1, 'last');
data.ref(k) = ref.ref(i_mostRecent);
end
Any tips on how to get rid of the for-loop and speed things up? Thanks a lot in advance!

 採用された回答

Hans Meier
Hans Meier 2019 年 10 月 21 日

0 投票

Ok, here's one solution:
data.ref = interp1(ref.TIME, ref.ref data.TIME, 'previous');

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

質問済み:

2019 年 10 月 21 日

回答済み:

2019 年 10 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by