how to use table2timetable from a cvs file
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I am really having a hard time finding out the proper way to use the table2timetable function.
I have this table with hourly data readings, where the column 1 is the year, col 2 is the month, col 3 is the day and col 4 is hour ( col 5 and 6 are the is the day or the year and hour of the year but i believe that is useless).
I am trying to convert it to a time table to be able to calculate daily and montly averages easily, but I just can't find the way to do it properly.
2005 5 20 17 140 3353 35.3 7.7 18 17.6 826 0 2.6 211 0 705 116 589 60 37.8 98.5
2005 5 20 18 140 3354 35.7 7.6 18 17.7 826 0 2 121 0 446 90 356 60 24.2 102.5
2005 5 20 19 140 3355 34 7.9 20 17.3 826 0 2.6 187 0 178 62 117 58 10.7 107.2
2005 5 20 20 140 3356 32.1 8.7 23 17.1 826 0 3.2 168 1 1 1 0 10 0 112.3
2005 5 20 21 140 3357 30.8 10.6 29 17.5 826 0 1.2 227 1 0 0 0 0 0 119.1
2005 5 20 22 140 3358 29.5 10.6 31 17.1 826 0 0.8 218 1 0 0 0 0 0 127.4
2005 5 20 23 140 3359 28.2 10.3 33 16.6 826 0 0.8 261 1 0 0 0 0 0 139.1
2005 5 20 24 140 3360 26.9 10.3 35 16.2 826 0 0.6 148 2 0 0 0 0 0 154.5
2005 5 21 1 141 3361 25 9.9 38 15.3 826 0 0.8 176 2 0 0 0 0 0 -174.3
2005 5 21 2 141 3362 23.1 9.7 43 14.6 826 0 1.3 223 2 0 0 0 0 0 -164.4
2005 5 21 3 141 3363 21 9.1 46 13.5 825 0 1.3 248 3 0 0 0 0 0 -146.5
2005 5 21 4 141 3364 20 10.6 55 14 825 0 2.4 214 3 0 0 0 0 0 -133.2
2005 5 21 5 141 3365 19 11 60 13.9 825 0 1.5 218 3 0 0 0 0 0 -123.2
2005 5 21 6 141 3366 18.3 11.4 64 13.8 825 0 2.4 282 3 0 0 0 0 0 -115.6
2005 5 21 7 141 3367 18.6 11.4 63 14 825 0 1.7 246 4 16 16 0 3 3.9 -110.1
2005 5 21 8 141 3368 21.5 11.3 52 14.9 825 0 1.3 278 4 270 125 146 55 17.2 -105.2
2005 5 21 9 141 3369 24.4 11.9 46 16.2 825 0 1.5 288 0 516 55 461 60 30.7 -101.1
2005 5 21 10 141 3370 27 9.8 34 16 825 0 2.2 222 0 739 73 666 60 44.5 -97.1
2005 5 21 11 141 3371 29.3 9.1 28 16.4 825 0 1 240 0 913 93 820 60 58.4 -93.1
2005 5 21 12 141 3372 31.3 8.9 25 16.9 825 0 1.7 216 0 1027 109 918 60 72.3 -87.5
2005 5 21 13 141 3373 32.8 8.7 23 17.3 825 0 1.3 173 0 1078 127 950 60 86 -65.2
TimeTable = table2timetable(MX0001hour)
0 comentarios
Respuestas (1)
Star Strider
el 23 de Sept. de 2019
It would be best to read it using readtable.
Assuming that you did not do that and read it in as a matrix, this may do what you want:
M = [2005 5 20 17 140 3353 35.3 7.7 18 17.6 826 0 2.6 211 0 705 116 589 60 37.8 98.5
2005 5 20 18 140 3354 35.7 7.6 18 17.7 826 0 2 121 0 446 90 356 60 24.2 102.5
2005 5 20 19 140 3355 34 7.9 20 17.3 826 0 2.6 187 0 178 62 117 58 10.7 107.2
2005 5 20 20 140 3356 32.1 8.7 23 17.1 826 0 3.2 168 1 1 1 0 10 0 112.3
2005 5 20 21 140 3357 30.8 10.6 29 17.5 826 0 1.2 227 1 0 0 0 0 0 119.1
2005 5 20 22 140 3358 29.5 10.6 31 17.1 826 0 0.8 218 1 0 0 0 0 0 127.4
2005 5 20 23 140 3359 28.2 10.3 33 16.6 826 0 0.8 261 1 0 0 0 0 0 139.1
2005 5 20 24 140 3360 26.9 10.3 35 16.2 826 0 0.6 148 2 0 0 0 0 0 154.5
2005 5 21 1 141 3361 25 9.9 38 15.3 826 0 0.8 176 2 0 0 0 0 0 -174.3
2005 5 21 2 141 3362 23.1 9.7 43 14.6 826 0 1.3 223 2 0 0 0 0 0 -164.4
2005 5 21 3 141 3363 21 9.1 46 13.5 825 0 1.3 248 3 0 0 0 0 0 -146.5
2005 5 21 4 141 3364 20 10.6 55 14 825 0 2.4 214 3 0 0 0 0 0 -133.2
2005 5 21 5 141 3365 19 11 60 13.9 825 0 1.5 218 3 0 0 0 0 0 -123.2
2005 5 21 6 141 3366 18.3 11.4 64 13.8 825 0 2.4 282 3 0 0 0 0 0 -115.6
2005 5 21 7 141 3367 18.6 11.4 63 14 825 0 1.7 246 4 16 16 0 3 3.9 -110.1
2005 5 21 8 141 3368 21.5 11.3 52 14.9 825 0 1.3 278 4 270 125 146 55 17.2 -105.2
2005 5 21 9 141 3369 24.4 11.9 46 16.2 825 0 1.5 288 0 516 55 461 60 30.7 -101.1
2005 5 21 10 141 3370 27 9.8 34 16 825 0 2.2 222 0 739 73 666 60 44.5 -97.1
2005 5 21 11 141 3371 29.3 9.1 28 16.4 825 0 1 240 0 913 93 820 60 58.4 -93.1
2005 5 21 12 141 3372 31.3 8.9 25 16.9 825 0 1.7 216 0 1027 109 918 60 72.3 -87.5
2005 5 21 13 141 3373 32.8 8.7 23 17.3 825 0 1.3 173 0 1078 127 950 60 86 -65.2];
T1 = array2table(M); % Create Table From MAtrix
DT = table(datetime([M(:,1:4), zeros(size(T1,1),2)])); % Create ‘datetime’ Table
T2 = [DT, T1(:,7:end)]; % Horizontally Concatenate
TT = table2timetable(T2); % Convert To ‘datetime’
Now, you should be able to do what you want with the timetable, ‘TT’.
0 comentarios
Ver también
Categorías
Más información sobre Numeric Types en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!