Extract rainfall values and the corresponding date from a time series when it satisfies certain condition
2 views (last 30 days)
Show older comments
martin atam
on 29 Jun 2016
Commented: Star Strider
on 30 Jun 2016
I have a daily time series data of one rain gauge station for 113 years. I want to extract those rainfall values and the corresponding dates only for those rainfalls which have a value greater than 2.5 mm and count the number of days with rainfall values greater than 2.5 mm for each year. The data is in .xlsx format and sample data is attached here.
Any help will be highly appreciated.
0 Comments
Accepted Answer
Star Strider
on 29 Jun 2016
This required a few extra lines because the original date strings didn’t have uniform formats (so the regexp call).
This works:
[d,s,r] = xlsread('martin atam Rainfall.xlsx');
rain = d; % Daily Rainfrall
dc = regexp(s, {'/|-'}, 'split'); % Pares Dates
dm = cellfun(@(x)sprintf('%2s/%2s/%4s\n', x{:}), dc, 'UniformOutput',false); % Uniform Date Strings
dn = datenum(dm, 'dd/mm/yyyy'); % Date Numbers
% dns = datestr(dn(1:15)) % Check Conversion (Optional)
rain25idx = rain > 2.5; % Logical Index Vector
rain_dv = datevec(dn(rain25idx)); % Rain Day Years
[Uyr,ia,ic] = unique(rain_dv(:,1), 'stable'); % Create Indices (‘ic’) To Tally
hc = accumarray(ic, 1); % Count Rain Days By Year
Out = [Uyr, hc]; % Years & Rain Days
Out_Check = Out(1:10,:) % Sample Output (Optional)
Out_Check =
1901 88
1902 106
1903 77
1904 67
1905 93
1906 92
1907 113
1908 89
1909 92
1910 86
4 Comments
Star Strider
on 30 Jun 2016
My pleasure.
An Excel formatting problem is something I’d not considered.
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!