Inefficient tall timetable lookup script, how to optimize?

3 次查看(过去 30 天)
Hi all,
I have two tables defined, one tall timetable tableA (1Mx18) and one regular table tableB (46x5).
  • tableA contains sensor observations logged with a timestamp, sensorID and its measurements (16 features).
  • tableB contains a log where each sensor is located in time.
Goal is to horconcat the location and sublocation from tableB to tableA within the period of the specific sensorID (tableB.startDate, tableB.endDate). In the mentioned example here above, the location of observations 1 and 2 from tableA must be 'N105'. To do so, I've written a very inefficient loop which checks for all rows in A if the timestamp is within the timeperiod in tableB and if the sensorID matches:
tableA = gather(talltimetableA);
for kk = 1:size(tableA,1)
for jj = 1:size(tableB,1)
if tableA.sensorID(kk) == tableB.sensorID(jj) && isbetween(tableA.TimeStamp(kk),tableB.StartDate(jj),tableB.EndDate(jj)) == 1
tableA.Location(kk) = tableB.Location(jj);
tableA.SubLocation(kk) = tableB.SubLocation(jj);
end
end
end
I need a 30-minute resolution at minimum for the observations in tableA. I'm pretty sure this script can optimized such that the script does not need 19 hours to be evaluated.
Thanks in advance,
Bas

回答(1 个)

Star Strider
Star Strider 2018-11-11
I cannot follow what you want to do well enough to provide any specific code. However, the join (link) function or one of its friends (linked to in and at the end of that page) are probably able to do what you want.
  1 个评论
BasO
BasO 2018-11-11
编辑:BasO 2018-11-11
Thank you for your reply, however join needs unique keys to join tableB to tableA. I've updated the question to provide more clarity.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by