Merging two tables based on time interval

2 views (last 30 days)
Ivo Kuiper on 30 Nov 2015
Answered: Udit Gupta on 30 Nov 2015
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.

Udit Gupta on 30 Nov 2015
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.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by