duration of rain. help

6 次查看(过去 30 天)
Nikita
Nikita 2024-3-7
Good afternoon, I have a file. It is not possible to find the average monthly duration of rain and its intensity.
Maybe someone can help. Thank you in advance
  2 个评论
Dyuman Joshi
Dyuman Joshi 2024-3-7
编辑:Dyuman Joshi 2024-3-7
It's not clear (atleast to me) what you have asked/want to do.
Please clearly specify what the objective is, mention the code that you have written yet and state the issue you are facing.
Nikita
Nikita 2024-3-7
I cannt't undenstand how calculation duration of rain in matlab code

请先登录,再进行评论。

采纳的回答

Mathieu NOE
Mathieu NOE 2024-3-7
hello
this is one way to do it - just plain simple matlab functions .
Of course , someone fluent with timetables can do it also , probably in few lines
this is my "old fashioned" way....
I don't see how rain intensity appears in your data - can you explain what are columns 9 to 16 ?
for the time being I simply computed the total amount of minutes of rain for each month and each year
% store data (year / month / total rain duration (minutes)
code done so far
T = readmatrix('rain.xlsx',"NumHeaderLines",2);
% cols : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
% id Year Mn Da Rain hr.min_start hr.min_finish
years = T(:,2);
month = T(:,3);
hr_min_start = T(:,17);
hr_min_finish = T(:,18);
[year_u,ia,ic] = unique(years);
out = [];
% loop over the years
for k = 1:numel(year_u)
% extract rows
rows_y = find(abs(years - year_u(k))<1); % more robust than == 0
% loop over the months
for mk = 1:12
month_list = month(rows_y);
% extract rows
rows_m = find(abs(month_list - mk)<1); % more robust than == 0
if ~isempty(rows_m) % we have data
hr_min_start_m = hr_min_start(rows_m); % extract start time
start_minutes = myconvert(hr_min_start_m); % convert to minutes
hr_min_finish_m = hr_min_finish(rows_m); % extract finish time
finish_minutes = myconvert(hr_min_finish_m); % convert to minutes
duration_minutes = finish_minutes - start_minutes;
% some duration appears negative simply because 0:00 is same
% as 24:00 , so we have to complement with 24*60 = 1440
% minutes
ind = (duration_minutes<0);
duration_minutes(ind) = duration_minutes(ind) + 1440;
total_duration_minutes = sum(duration_minutes);
flag_store = 1;
else
total_duration_minutes = 0;
flag_store = 0;
end
% store data (year / month / duration(minustes)
if flag_store~= 0
out = [out; [year_u(k) mk total_duration_minutes]];
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function out_minutes = myconvert(time)
% time format is like 22.40 (hours = 22 , minutes = 40)
% convert this in minutes only
hh = floor(time); % hours
mm = time - hh; % minutes
out_minutes = mm+60*hh;
end
  8 个评论
Nikita
Nikita 2024-3-27
Yes, of course. Many thanks

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2024-3-27
You might look into splitapply, grpstats, groupsummary, and findgroups. They are very useful functions to know about! 🙂
  1 个评论
Image Analyst
Image Analyst 2024-3-27
If an Answer solves your original question, then could you please click the "Accept this answer" link/button to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one - Matthew's) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by