Analyzing Rainfall data and sorting the data appropriately

Hello,
I need to know how do I sort the rainfall data attached into monthly data and find out the dry days, maximum rainfall, all event sizes where rainfall is greater than 1mm and 10,50,90 percentile data. The rainfall data has a 6 min time step. Thanks

 Accepted Answer

Look into timetables, groupsummary and perhaps grpstats.

4 Comments

As I am new to Matlab, I tried solving it with for loop. I've written a basic code to help me through with it. I have attached it for your reference, the only problem is that the data is difficult to interpret so I think I would need to perhaps plot it or something.
Your spreadsheet is a mix of csv and spreadsheet. Can you share the original csv?
Hey Cris,
No I don't have the csv file, I was just given this spreadsheet :/
It just gets a little more complicated to read in because the date and number are in double quotes, so they are getting treated as a string, and read in as a single column.
Here's what I had to do in R2021b to get it into MATLAB
data = readtable('Rainfall 1994.xlsx','Range','A:A')
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
data = 87600×1 table
Date_RainfallMm_6Minutes ____________________________________ {'1/01/1994 00:00, 0.00000000'} {'1/01/1994 00:06, 0.00000000'} {'1/01/1994 00:12, 0.00000000'} {'1/01/1994 00:18, 0.00000000'} {'1/01/1994 00:24, 0.00000000'} {'1/01/1994 00:30, 0.00000000'} {'1/01/1994 00:36, 0.00000000'} {'1/01/1994 00:42, 0.00000000'} {'1/01/1994 00:48, 0.00000000'} {'1/01/1994 00:54, 0.00000000'} {'1/01/1994 01:00, 0.00000000'} {'1/01/1994 01:06, 0.00000000'} {'1/01/1994 01:12, 0.00000000'} {'1/01/1994 01:18, 0.00000000'} {'1/01/1994 01:24, 0.00000000'} {'1/01/1994 01:30, 0.00000000'}
DR = split(data{:,1},',');
Date = datetime(DR(:,1),'InputFormat','M/dd/yyyy HH:mm');
Rainfall = str2double(DR(:,2));
RF = timetable(Date,Rainfall)
RF = 87600×1 timetable
Date Rainfall ____________________ ________ 01-Jan-1994 00:00:00 0 01-Jan-1994 00:06:00 0 01-Jan-1994 00:12:00 0 01-Jan-1994 00:18:00 0 01-Jan-1994 00:24:00 0 01-Jan-1994 00:30:00 0 01-Jan-1994 00:36:00 0 01-Jan-1994 00:42:00 0 01-Jan-1994 00:48:00 0 01-Jan-1994 00:54:00 0 01-Jan-1994 01:00:00 0 01-Jan-1994 01:06:00 0 01-Jan-1994 01:12:00 0 01-Jan-1994 01:18:00 0 01-Jan-1994 01:24:00 0 01-Jan-1994 01:30:00 0
I also turned the data back into the original csv by removing the equation and the double quotes. It's a much simpler import process.
rf = readtimetable('Rainfall 1994.csv')
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
rf = 87600×1 timetable
Date RainfallMm_6Minutes ________________ ___________________ 01/01/1994 00:00 0 01/01/1994 00:06 0 01/01/1994 00:12 0 01/01/1994 00:18 0 01/01/1994 00:24 0 01/01/1994 00:30 0 01/01/1994 00:36 0 01/01/1994 00:42 0 01/01/1994 00:48 0 01/01/1994 00:54 0 01/01/1994 01:00 0 01/01/1994 01:06 0 01/01/1994 01:12 0 01/01/1994 01:18 0 01/01/1994 01:24 0 01/01/1994 01:30 0
Once the data is imported, process the data however you like. MATLAB has some useful functions you may consider looking into, like retime, quantile, and groupsummary. For example, to turn your 6 minute data set into a daily data set, I might do the following
dailyRF = retime(rf,"daily","sum")
dailyRF = 365×1 timetable
Date RainfallMm_6Minutes ________________ ___________________ 01/01/1994 00:00 0.2 02/01/1994 00:00 0 03/01/1994 00:00 0 04/01/1994 00:00 0 05/01/1994 00:00 0 06/01/1994 00:00 0 07/01/1994 00:00 0 08/01/1994 00:00 0 09/01/1994 00:00 0 10/01/1994 00:00 0.86 11/01/1994 00:00 0 12/01/1994 00:00 0 13/01/1994 00:00 0 14/01/1994 00:00 0.34 15/01/1994 00:00 13.88 16/01/1994 00:00 0

Sign in to comment.

More Answers (1)

Thank you so much Cris!
I needed the data in 6 hour intervals and I was able to do that and plot the the data as well. Although when I use the percentile function it gives me the following error.
Error using internal.stats.dominantType (line 14)
Subscripting into a table using one subscript (as in t(i)) is not supported. Specify a row subscript
and a variable subscript, as in t(rows,vars). To select variables, use t(:,i) or for one variable
t.(i). To select rows, use t(i,:).
Error in prctile (line 77)
yproto = internal.stats.dominantType(x,p); % prototype output
I dont know what exactly what I'm doing wrong. I just want the 10,50 and 90th percentile values.
Also, one last thing: Is this the correct syntax for the Groupstat command. G = grpstats( eventtable, 'RainfallMm_6Minutes', 0)
I just want to have a table with the dry days which have the value 0.
Thank you so so so much :)

4 Comments

If you are using my code, the data is stored in a table. The error message indicates you are not using the correct syntax to access the data. See this page about accessing data in a table. The details about the expected syntax are included in the error message.
Hello Cris,
Hopefully you're still there. I need help again. I tried creating a for loop that check each rainfall value. It basically needs to calculate the duration of rain events and the interval or dry period between those rain events. I wanted to create another table that shows the duration and the sum of rainfall value in that rain event. I have generated a graph as well. I am not able to write the code for obtaining the duration and sum in another table. I get too confused. I would really appreciate your help here.
Thanks
Perhaps provide a simple example? It is not exactly clear to me what it is you want to do.
How did you create the graph?
Basically I need to group rain events and dry events.In other words find the storm period and the interval between the storm periods.
I created the graph using the code below:
plot (event.Date, event.RainfallMm_6Minutes)
ylabel('Mean Rainfall (*mm)');
% Add equally spaced ticks (one every ~30 days)
xData = linspace(event.RainfallMm_6Minutes(1),event.RainfallMm_6Minutes(end),10);
d.XTick = xData;
% Add labels
fsize=12;
tx = get(gca,'XTickLabel'); set(gca,'XTickLabel',tx,'fontsize',fsize,'FontWeight','bold');
ty = get(gca,'XTickLabel'); set(gca,'XTickLabel',ty,'fontsize',fsize,'FontWeight','bold');
datetick('x','dd mmm yy','keeplimits','keepticks');
% Add gridlines
hAx=gca;
set(hAx,'YGrid','on','XGrid','on')
set(hAx,'xminorgrid','on','yminorgrid','on')

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!