Calculate a value from a table column based on defined intervals give by another table

1 view (last 30 days)
Hi,
I've got a table T with varius columns, 1'st is Time (it's not a timetable necessarly, in thsi specific case it's not, it's time in s but not as timetable).
I've got a 2'nd table T2 with 2 columns which in essence gives the time intervals (start and end lap times in this case, which will match the values in the previus table T as they are extrated from it).
What I'm trying to do is for each set of start/end time intervals in T2 calculate another column (for the given interval) in table T (max for example).
Thanks.

Accepted Answer

Chunru
Chunru on 28 Jun 2022
load("table T");
load("table T2");
head(T)
ans = 8×2 table
Time AmbientTemp ____ ___________ 0 15 0.1 15 0.2 15 0.3 15 0.4 15 0.5 15 0.6 15 0.7 15
head(T2)
ans = 8×3 table
Start_time End_time Lap_time __________ ________ ________ 424.9 958.9 08:54 970.9 1491.9 08:41 1498.9 2010.9 08:32 2022.9 2535.9 08:33 3509.8 4020.8 08:31 4031.8 4544.8 08:33 4555.8 5066.8 08:31 5079.8 5592.8 08:33
n = size(T2, 1);
T2_max = zeros(n, 1);
for i=1:size(T2, 1)
T2_max(i) = max(T.AmbientTemp(T.Time>=T2.Start_time(i) & T.Time<T2.End_time(i)));
end
T2.max = T2_max;
T2
T2 = 10×4 table
Start_time End_time Lap_time max __________ ________ ________ _____ 424.9 958.9 08:54 14.25 970.9 1491.9 08:41 15 1498.9 2010.9 08:32 14.25 2022.9 2535.9 08:33 14.25 3509.8 4020.8 08:31 21 4031.8 4544.8 08:33 17.25 4555.8 5066.8 08:31 17.25 5079.8 5592.8 08:33 17.25 6234.8 6752.8 08:38 21.75 6764.8 7284.8 08:40 18

More Answers (0)

Categories

Find more on Tables 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!