Extract rainfall values and the corresponding date from a time series when it satisfies certain condition

2 ビュー (過去 30 日間)
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.

採用された回答

Star Strider
Star Strider 2016 年 6 月 29 日
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 件のコメント
martin atam
martin atam 2016 年 6 月 30 日
I just found out that it is because of my excel date formatting option. Both the codes work fine for me. Thank you once again.
Star Strider
Star Strider 2016 年 6 月 30 日
My pleasure.
An Excel formatting problem is something I’d not considered.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by