Add NaN values in a timetable based on missing datetimes
14 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Steven Lord
2022 年 4 月 5 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Preprocessing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!