Retime puts all NaN

34 ビュー (過去 30 日間)
Andrea Cecilia
Andrea Cecilia 2020 年 4 月 1 日
回答済み: Peter Perkins 2020 年 4 月 14 日
Hi there,
I have a timetable with a dataset of a weather station, whose first rows are e.g.
tt(1:15,:)
ans =
15×11 timetable
Time Press T UR WSpeed WDir WGust RainRate Rain DP Rad UV
________________ ______ ______ __ ______ _____ ______ ________ ____ _______ ___ ___
12/01/0019 11:00 1009.3 3.6667 58 1.6093 202.5 8.0467 0.1 0 -3.824 NaN NaN
12/01/0019 11:05 1009.2 4.1111 59 0 NaN 0 0.08 0 -3.1779 NaN NaN
12/01/0019 11:10 1009.2 4.3333 53 6.4374 22.5 11.265 0 0 -4.3996 NaN NaN
12/01/0019 11:15 1009.2 4.3889 52 11.265 22.5 17.703 0 0 -4.6004 NaN NaN
12/01/0019 11:20 1009.2 4.4444 53 11.265 22.5 17.703 0 0 -4.2964 NaN NaN
12/01/0019 11:25 1008.9 4.7778 52 9.6561 22.5 16.093 0 0 -4.2398 NaN NaN
12/01/0019 11:30 1008.8 4.7778 52 11.265 22.5 17.703 0 0 -4.2398 NaN NaN
12/01/0019 11:35 1008.9 5.0556 52 9.6561 45 16.093 0 0 -3.9824 NaN NaN
12/01/0019 11:40 1008.8 5.1667 50 12.875 22.5 17.703 0 0 -4.4005 NaN NaN
12/01/0019 11:45 1008.8 5.3889 49 11.265 22.5 17.703 0 0 -4.4635 NaN NaN
12/01/0019 11:48 1008.6 5.6111 51 6.4374 22.5 11.265 0 0 -3.7267 NaN NaN
12/01/0019 11:49 1008.6 5.7778 50 11.265 45 14.484 0 0 -3.8367 NaN NaN
12/01/0019 11:50 1008.6 5.8333 49 6.4374 45 11.265 0 0 -4.0544 NaN NaN
12/01/0019 11:51 1008.6 5.9444 50 4.828 45 12.875 0 0 -3.6829 NaN NaN
12/01/0019 11:52 1008.6 5.9444 49 9.6561 45 12.875 0 0 -3.9521 NaN NaN
>>
as you can see, date times are every 5 minutes, but sometimes there are jumps (for example, from 11:30 to 11:40), or more continuous data (see last rows). What I need to do is fill the gaps with NaN lines, and put all the dataset every five minutes. Id est, I need to create a new line 11:35 between 11:30 and 11:40 with all NaN for the variables, and aggregate the too continuous data for example with mean values.
I know I can obtain this using retime function, so I gave
Times = [t0:minutes(5):tf];
tt=retime(tt,Times,'fillwithmissing');
where t0 and tf are datetime extremals.
What I am getting from this is
>> tt(1:15,:)
ans =
15×11 timetable
Time Press T UR WSpeed WDir WGust RainRate Rain DP Rad UV
______________ _____ ___ ___ ______ ____ _____ ________ ____ ___ ___ ___
12/01/19 11:00 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
12/01/19 11:05 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
12/01/19 11:10 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
12/01/19 11:15 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
12/01/19 11:20 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
12/01/19 11:25 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
12/01/19 11:30 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
12/01/19 11:35 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
12/01/19 11:40 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
12/01/19 11:45 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
12/01/19 11:50 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
12/01/19 11:55 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
12/01/19 12:00 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
12/01/19 12:05 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
12/01/19 12:10 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
>>
why are there all NaN now??
Can you help me?
Thanks,
Andrea
  1 件のコメント
Mohammad Sami
Mohammad Sami 2020 年 4 月 1 日
編集済み: Mohammad Sami 2020 年 4 月 1 日
Perhaps there are some second values in your time values. This might cause it not to find the values at the specified five minute intervals. May need to round the time using dateshift function,
Try specifiying time step instead of a time array
dt = minutes(5);
TT2 = retime(TT1,'regular','fillwithmissing','TimeStep',dt);

サインインしてコメントする。

回答 (1 件)

Peter Perkins
Peter Perkins 2020 年 4 月 14 日
As Mohammad says, you must have times that are not exactly at the 5 minute marks. That's the danger of a short display format.
retime fills with missing values by default anywhere it has to fill in a value. In your case, that's everywhere. You could either clean up the original row times, or you could use the 'nearest' method to shift values from your irregular times to the regular 5-min times. Of course, if you use 'nearest' AND add the missing rows all in one step, you will get non-NaN values filled in for the times where the missing rows were. I think that's not what you want. And also you need to aggregate (mean? max? first?). Three things.
So, do this in steps. First clean up the extra seconds.
tt.Time = dateshift(tt.Time,'start','minute','nearest');
Then aggregate the rows not on 5-min increments. Since mean returns NaN for empty, you can also add the missing rows.
tt = retime(tt,'regular','mean','TimeStep',minutes(5))
That should do it.

カテゴリ

Help Center および File ExchangeTrigonometry についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by