How to filter dataset into specific time range and scan for missing values?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Ravindu Lokuliyana
el 20 de Feb. de 2019
Editada: Ravindu Lokuliyana
el 26 de Feb. de 2019
Hi there,
I got a large set of measured data in a text file with 3 hour time intervals. Here some measurements are not recorded and some time values are not in a sequence.
I need to delete the time intervals which are not in the sequence and then add some value for missing time intervals.
I have tried with the 'unique' matlab function, but failed to achieve it. Hereby attached the sample file of the dataset.
I would greatly appreciate if anyone can help me to achieve this.
Thank you.
0 comentarios
Respuesta aceptada
Peter Perkins
el 21 de Feb. de 2019
Timetables and retime were born to do this:
>> X = [89 2 03 0030 1.6955 5.08; ...
89 2 03 0330 1.8172 4.39; ...
89 2 03 0630 1.2139 4.15; ...
89 2 03 0830 1.1986 4.33; ...
89 2 03 0930 0.9349 4.37; ...
89 2 03 1230 0.9610 4.17; ...
89 2 03 2130 0.8554 4.39];
>> time = datetime(1900+X(:,1),X(:,2),X(:,3),fix(X(:,4)/100),X(:,4)-100*fix(X(:,4)/100),0);
>> tt = timetable(X(:,4),X(:,5),'RowTimes',time)
tt =
7×2 timetable
Time Var1 Var2
____________________ ____ ______
03-Feb-1989 00:30:00 30 1.6955
03-Feb-1989 03:30:00 330 1.8172
03-Feb-1989 06:30:00 630 1.2139
03-Feb-1989 08:30:00 830 1.1986
03-Feb-1989 09:30:00 930 0.9349
03-Feb-1989 12:30:00 1230 0.961
03-Feb-1989 21:30:00 2130 0.8554
>> time3 = time(1):hours(3):time(end);
>> tt3 = retime(tt,time3,'fillwithmissing')
tt3 =
8×2 timetable
Time Var1 Var2
____________________ ____ ______
03-Feb-1989 00:30:00 30 1.6955
03-Feb-1989 03:30:00 330 1.8172
03-Feb-1989 06:30:00 630 1.2139
03-Feb-1989 09:30:00 930 0.9349
03-Feb-1989 12:30:00 1230 0.961
03-Feb-1989 15:30:00 NaN NaN
03-Feb-1989 18:30:00 NaN NaN
03-Feb-1989 21:30:00 2130 0.8554
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!