When trying to fill timetable gaps retime puts everything NaN
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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:
Into this:
Any clue of what is happening or how to solve this?
0 commentaires
Réponses (1)
Star Strider
le 1 Fév 2024
That is what the 'fillwithmissing' option does.
2 commentaires
Star Strider
le 1 Fév 2024
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.
.
Voir également
Catégories
En savoir plus sur Dates and Time 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!