Sum up measurements to daily basis (measurements each 10 minutes)

1 次查看(过去 30 天)
Hi,
I want to sum up measurements (of precipitation), that is measured each 10 minutes in one month, to a daily basis.
Sometimes there is a whole in the dataset, but each measurement is related to a date in the format 'yyyy-mm-ddTHH:MM:SSZ'.
I have already converted the date format to a number with the help of the function datenum.
The time and measurements is in a table of the size 4464x2, which corresponds to measurements each 10 minutes in one month (other datasets is of the size 2518x2).
Column 1 is the time and column 2 is the amount of precipitation.
How do I easily sum up, so that I get the amount of precipitation in one day over a month (corresponding to 30 to 31 rows)?

回答(1 个)

ag
ag 2024-10-3
Hi Emma,
To sum up the precipitation measurements on a daily basis from a dataset where each measurement is taken every 10 minutes, you can use MATLAB's "dateshift" function to extract the date from the datetime and then use MATLAB's "groupsummary" function to sum the precipitation for each day.
The below code snippet explains how to achieve this using dummy data:
%dummy data
numMeasurements = 4464;
startDate = datenum(2023, 1, 1, 0, 0, 0);
datenumArray = startDate + (0:10:(numMeasurements-1)*10)'/1440;
precipitationArray = rand(numMeasurements, 1); % Random precipitation values
T = table(datenumArray, precipitationArray, 'VariableNames', {'Datenum', 'Precipitation'});
% Convert 'Datenum' to 'datetime'
T.Time = datetime(T.Datenum, 'ConvertFrom', 'datenum');
% Add a new column to group by date
T.Date = dateshift(T.Time, 'start', 'day');
% Sum the precipitation for each day
dailyPrecipitation = groupsummary(T, 'Date', 'sum', 'Precipitation');
% Display the result
disp(dailyPrecipitation);
Date GroupCount sum_Precipitation ___________ __________ _________________ 01-Jan-2023 144 78.865 02-Jan-2023 144 69.27 03-Jan-2023 144 70.836 04-Jan-2023 144 74.875 05-Jan-2023 144 70.657 06-Jan-2023 144 72.983 07-Jan-2023 144 73.88 08-Jan-2023 144 71.338 09-Jan-2023 144 70.672 10-Jan-2023 144 70.006 11-Jan-2023 144 80.142 12-Jan-2023 144 69.565 13-Jan-2023 144 65.849 14-Jan-2023 144 76.129 15-Jan-2023 144 76.818 16-Jan-2023 144 73.713 17-Jan-2023 144 71.427 18-Jan-2023 144 77.961 19-Jan-2023 144 78.999 20-Jan-2023 144 67.977 21-Jan-2023 144 68.104 22-Jan-2023 144 78.649 23-Jan-2023 144 68.548 24-Jan-2023 144 72.169 25-Jan-2023 144 71.941 26-Jan-2023 144 76.214 27-Jan-2023 144 70.235 28-Jan-2023 144 73.883 29-Jan-2023 144 72.191 30-Jan-2023 144 69.82 31-Jan-2023 144 74.523
For more details, please refer to the following MathWorks documentations:
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by