When trying to fill timetable gaps retime puts everything NaN
6 次查看(过去 30 天)
显示 更早的评论
I have a big timetable with different kind of data as 8xdouble, char arrays etc
The timetable is organized in seconds with data from several days but there are gap of the days that there is no data. I want to fill this gaps with NaN so whe I plot the timetable all the data is shown in block, without line filling the time gaps.
I'm doing:
TT_nan=retime(TT,'secondly','fillwithmissing');
And this adds the desired NaNs in the rows time gaps but also converts the rest of the columns in NaN
Transforms this:
![ORIGINAL TABLE](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1605891/ORIGINAL%20TABLE.png)
Into this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1605896/image.png)
Any clue of what is happening or how to solve this?
0 个评论
回答(1 个)
Star Strider
2024-2-1
That is what the 'fillwithmissing' option does.
2 个评论
Star Strider
2024-2-1
I am not certain what is going on with that file, since I do not have it to work with.
Simulating that seems to work, although the fix for it is slightly cumbersome. The problem seems to be that the times are not exact seconds (adding random positive microseconds here to simulate that), and this causes problems for retime —
t = datetime(2023,9,6,14,25,0)+seconds(0:10).'+rand(11,1)*1E-6; % Add Random Microseconds
data = rand(numel(t), 3)*1E+3;
T1 = table(data);
T1 = addvars(T1, t, 'before',1);
TT1 = table2timetable(T1)
TT1r = retime(TT1, 'secondly', 'fillwithmissing')
This reproduces the observed behaviour.
The retime function (for whatever reason) then considers them missing and apparently cannot effectively resample them. Artifically rounding them to whole seconds (that apparently requires regenerating the entire date and time entries from their components), then works with retime to produce the desired result.
Starting back from the original ‘T1’ table data and fixing the seconds —
s = floor(second(T1.t)); % Extract The 'second' Field, Eliminate The Fracional Seconds
[h,m] = hms(T1.t); % Return Components
[y,m,d] = ymd(T1.t); % Return Components
T1.t = datetime(y,m,d,h,m,s) % Re-Create New 'datetime' Array
TT1 = table2timetable(T1);
TT1r = retime(TT1, 'secondly', 'fillwithmissing')
Apparently, if the times are not exactly in seconds, retime considers them missing. The fix for that is a bit ‘kludgy’, however this approach seems to work. This may be a ‘bug’ in retime that you incidentally discovered.
.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Timetables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!