For loop on timetable
이전 댓글 표시
Hello,
So I have hourly data and rain in mm. I want to make a for loop that checks if the rainfall is equal to 0 or greater than 1. If it is 0 for 3 consecutive hours then the time is added and labelled as "Dry Event". If the rain is greater than 1mm along with consecutive values, the those values nad the times are added is labelled as "rain event".
This is my code uptil now:
rf = readtimetable('C:\Users\Priya\Downloads\Thesis\Sydney Rain 1994.csv');
dailyRF = retime(rf,"daily","sum");
dt=hours(1);
event= retime(dailyRF,"regular","sum", "TimeStep",dt);
I am trying to attempt the below for loop, which I know is wrong because it keeps giving me errors. I tried using groupstats but I couldn't get the right answer. I am new to Matlab and the code does have basic errors, I know.
i = 1:size(event)
if event.RainfallMm_6Minutes==0
sum(event.Date)
'Dry Event'
elseif event.RainfallMm_6Minutes >= 1
sum(event.Date)
'Rain Event'
end
Thank you!!
답변 (1개)
KSSV
2021년 11월 4일
rf = readtimetable('Sydney Rain 1994.csv');
dailyRF = retime(rf,"daily","sum");
dt=hours(1);
event= retime(dailyRF,"regular","sum", "TimeStep",dt);
T = timetable2table(event) ;
t = T.(1) ;
R = T.(2) ;
% Arrange three time steps as moving window (the belo will give indices)
idx = bsxfun(@plus, (1 : 3), (0 : numel(R) - 3).');
iwant = sum(R(idx),2) ; % this will give you sum of three consecutive time steps
t = t(idx) ;
% find when consecutive days is zero
id1 = iwant==0 ; % logical indices
id2 = iwant > 0 ; % logical indices
t(id1,1) % this will give time step of first day where rainfall is zero three continuous steps
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!