Extract hourly data from minute data over a year

3 views (last 30 days)
Hi, I have raw weather data (titled 'weather_data_2019') from 2019 that is documented by every minute. The txt file is formatted so it gives the data and time such as:
2019-01-01 hh:mm:ss, recno, wind speed, par, wsdv, wddv, temp, rain delta, rh, wind dir.
For example this is the first line of data:
2019-01-01 00:00:00,81598,0.0,0.0,0.0,0.0,32.86,0.0,96.8,0.0
I also have attached a txt file for the first day (the file is too large to allow me to upload the whole year). I have been trying to have my code so that it opens the file and only extracts all the data every day at every hour on the dot, so that my code can cut down on the amount of data it needs to go through. So far I'm not having any luck with this, any ideas as to how this can be achieved? Thank you!

Accepted Answer

Star Strider
Star Strider on 27 Oct 2020
Try this:
T1 = readtable('weather_data_2019.txt');
Idx = minute(T1.Datetime) == 0;
OutTable = T1(Idx,:)
producing (for this file):
OutTable =
24×10 table
Datetime RecNbr WS_mph_Avg PAR_Den_Avg WS_mph_S_WVT WindDir_SD1_WVT AirTF_Avg Rain_in_Tot RH WindDir_D1_WVT
___________________ ______ __________ ___________ ____________ _______________ _________ ___________ _____ ______________
2019-01-01 00:00:00 81598 0 0 0 0 32.86 0 96.8 0
2019-01-01 01:00:00 81658 2.759 0 2.759 0.014 33.48 0 96.9 151.8
2019-01-01 02:00:00 81718 3.266 0 3.266 0.02 35.48 0.01 97.1 139
2019-01-01 03:00:00 81778 6.367 0 6.367 0 40.04 0 96.6 172.7
2019-01-01 04:00:00 81838 4.19 0 4.19 0.014 41.31 0 96.4 144.9
2019-01-01 05:00:00 81898 2.044 0 2.044 0 41.15 0 96.5 15.32
2019-01-01 06:00:00 81958 2.878 0 2.878 0 38.8 0 95.8 288.1
2019-01-01 07:00:00 82018 4.161 0.669 4.161 0 37.77 0 97.8 297.4
2019-01-01 08:00:00 82078 5.711 43.48 5.711 0 37.55 0 97.4 264.2
2019-01-01 09:00:00 82138 5.651 261.6 5.651 0 37.9 0 95.6 277.4
2019-01-01 10:00:00 82198 7.023 675 7.023 0.014 43.11 0 90.5 267.2
2019-01-01 11:00:00 82258 13.73 825 13.73 0 48.84 0 76.64 304.4
2019-01-01 12:00:00 82318 22.08 146.5 22.08 0.014 48.19 0 64.24 307.5
2019-01-01 13:00:00 82378 18.83 778.7 18.83 0 46.75 0 52.31 324
2019-01-01 14:00:00 82438 21.75 207.4 21.75 0.014 44.49 0 56.24 347.6
2019-01-01 15:00:00 82498 16.8 293.7 16.8 0 41.77 0 57.66 313.4
2019-01-01 16:00:00 82558 11.11 46.17 11.11 0 40.19 0 58.81 298.2
2019-01-01 17:00:00 82618 13.52 0 13.52 0 38.2 0 58.6 311.6
2019-01-01 18:00:00 82678 10.51 0 10.51 0 37.77 0 59.42 273.9
2019-01-01 19:00:00 82738 8.45 0 8.45 0 36.54 0 62.06 297.2
2019-01-01 20:00:00 82798 12.45 0 12.45 0 34.63 0 57.05 8.98
2019-01-01 21:00:00 82858 8.1 0 8.1 0 33.27 0 54.34 309.8
2019-01-01 22:00:00 82918 13.28 0 13.28 0 31.44 0 52.3 290
.
.

More Answers (0)

Categories

Find more on Graphics Object Identification in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!