Filling missing times in timetable with NaN using retime
조회 수: 25 (최근 30일)
이전 댓글 표시
I am trying to create rows in a timetable for days where data is missing. I have the attached table as an example.
Can anyone explain why the following does not work? Instead of getting one row filled with NaN for the only day missing data (15th Nov), all rows after the missing date are replaced with NaN.
clc;clear;clf
load('data.mat')
data.ChunkEnd(4:end)=data.ChunkEnd(4:end)+seconds(1); %think this is necessary because the timing is slightly off?
data_retime=retime(data,data.ChunkEnd(1):days(1):max(data.ChunkEnd),'fillwithmissing');
답변 (1개)
dpb
2022년 10월 7일
load(websave('data.mat','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1148080/data.mat'))
ttD=data_site_num_tt1; % just get a shorter variable name to work with
clear data_site_num_tt1;
rule=-1*double(second(ttD.ChunkEnd)==0); % don't round up 00 seconds rule
ttD.ChunkEnd=dateshift(ttD.ChunkEnd,'end','minute',rule); % round up any those with seconds
newt=datetime(ttD.ChunkEnd(1):days(1):ttD.ChunkEnd(end)); % fill in the time vector to match
ttD=retime(ttD,newt) % and retime -- will insert missing automagically
The above is a little esoteric with the use of the secondary rule argument and the logic test to set it so would not turn 23:59 into 24:00 and then 00:00 of the next day, granted, but figured may as well demonstrate a corner feature of retime while at it and had the opportunity.
One might just use regular timing and round to the next day since all are so near midnight; that's a decision the data owner has to decide about which date to report on.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Timetables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!