Add NaN values in a timetable based on missing datetimes
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Enrico Gambini
le 5 Avr 2022
Réponse apportée : Steven Lord
le 5 Avr 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 commentaires
Réponse acceptée
Steven Lord
le 5 Avr 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Preprocessing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!