Merging two tables based on time interval

1 次查看(过去 30 天)
I have two tables A and B. A consists of information about glucose measurements, B consists insulin medication settings. I want to couple a glucose measurement to the setting of the insulin perfusor. However the timing is different and there are more medication settings than glucose measurements.
Table A:
Patientnumber * MeasureGlucose * Time(using datenum) * TimeNormal
11112222 * 16,9 * 7.3626e+05 * 26-10-2015 17:57:00
11112222 * 21,5 * 7.3626e+05 * 26-10-2015 19:47:00
11112222 * 26,3 * 7.3626e+05 * 26-10-2015 22:09:00
11112222 * 15,6 * 7.3626e+05 * 26-10-2015 02:29:00
11112222 * 8,8 * 7.3626e+05 * 26-10-2015 06:10:00
Table B:
Patientnumber * PerfusorNovorapidDosisE_u * Time(using datenum) * TimeNormal
11112222 * 1 * 7.3626e+05 * 26-10-2015 17:44:00
11112222 * 2 * 7.3626e+05 * 26-10-2015 20:00:00
11112222 * 4 * 7.3626e+05 * 26-10-2015 22:12:00
11112222 * 4 * 7.3626e+05 * 27-10-2015 02:07:00
11112222 * 4 * 7.3626e+05 * 27-10-2015 04:05:00
11112222 * 4 * 7.3626e+05 * 27-10-2015 06:05:00
11112222 * 2 * 7.3626e+05 * 27-10-2015 08:10:00
How can I merge these tables in the following way:
1. Select time of measurement in table A.
2. Find a medication setting within 40 minutes after the measurement
3. If no medication setting available in step 2, use the previous medication setting
I hope someone can help me with this problem setting.

回答(1 个)

Udit Gupta
Udit Gupta 2015-11-30
You can use
t = interp1(sample_time,tableB.Time,'nearest');
if abs(sample_time-t <= 40/(24*60))
<Update medication setting using t>
else
<Use previous setting>
end
See interp1 documentation for more control.

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by