For loop on timetable
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!!
0 Kommentare
Antworten (1)
KSSV
am 4 Nov. 2021
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
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!