get interpolated values from timetable

6 vues (au cours des 30 derniers jours)
Ryan
Ryan le 1 Fév 2024
Modifié(e) : Stephen23 le 1 Fév 2024
I have a timetable (using readtimetable from a csv).
datetime, tempA, tempB
1/1/1990 9:00, 36, 12
1/1/1990 10:00, 28, 24
...
I have a time that I want to extract a interpolated temp. Lets say 1/1/1990 9:32. How can I get tempA and tempB as linearly interpolated given a random time. I dont necessarily want to resample all the data which I see you can do.

Réponse acceptée

Stephen23
Stephen23 le 1 Fév 2024
Modifié(e) : Stephen23 le 1 Fév 2024
INTERP1 accepts DATETIME objects:
dt = datetime(1990,1,1,[9;10],0,0);
A = [36;28];
B = [12;24];
T = table(dt,A,B)
T = 2×3 table
dt A B ____________________ __ __ 01-Jan-1990 09:00:00 36 12 01-Jan-1990 10:00:00 28 24
newT = datetime(1990,1,1,9,32,0)
newT = datetime
01-Jan-1990 09:32:00
newA = interp1(T.dt,T.A,newT)
newA = 31.7333
newB = interp1(T.dt,T.B,newT)
newB = 18.4000
You could even combine them into one INTERP1 call:
newAB = interp1(T.dt,T{:,["A","B"]},newT)
newAB = 1×2
31.7333 18.4000
Or you could use a TIMETABLE and RETIME:
TT = table2timetable(T)
TT = 2×2 timetable
dt A B ____________________ __ __ 01-Jan-1990 09:00:00 36 12 01-Jan-1990 10:00:00 28 24
newTT = retime(TT,newT,'linear')
newTT = 1×2 timetable
dt A B ____________________ ______ ____ 01-Jan-1990 09:32:00 31.733 18.4

Plus de réponses (0)

Catégories

En savoir plus sur Calendar dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by