Add NaN values in a timetable based on missing datetimes
조회 수: 17 (최근 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!