Add NaN values in a timetable based on missing datetimes
21 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Enrico Gambini
il 5 Apr 2022
Risposto: Steven Lord
il 5 Apr 2022
Hi guys.
Let's say that I have timetable with n rows containing hourly data starting from date "t1" and ending on date "t2", the datetime vector of the time table is not complete in the sense that some data on certain datetimes are missing.
Is there a simple way to create the complete timetable (i.e. having the complete hourly datetime vector starting from t1 and ending at t2) where the missing datetimes data are filled with NaN?
Hope that the question is clear. Thank you!
0 Commenti
Risposta accettata
Steven Lord
il 5 Apr 2022
Here's some sample data.
MeasurementTime = datetime({'2015-12-18 08:03:05'; ...
'2015-12-18 10:03:05'; ...
'2015-12-18 12:03:05'});
Temp = [37.3;39.1;42.3];
Pressure = [30.1;30.03;29.9];
WindSpeed = [13.4;6.5;7.3];
TT = timetable(MeasurementTime,Temp,Pressure,WindSpeed)
Let's create a new time vector.
newTimeVector = (MeasurementTime(1):hours(1):MeasurementTime(3)).'
Use retime to create a new time table with the newTimeVector as its time vector. By default new rows in the new timetable will be filled with missing data. There are other methods you can select to generate the new data.
TT2 = retime(TT, newTimeVector)
TT3 = retime(TT, newTimeVector, 'linear') % Linear interpolation
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Timetables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!