Calculate consecutive values from annual data to monthly have a yearly timetable (events(1X365)) and I want to find how many consecutive values are equal to 1 for every mont

2 Ansichten (letzte 30 Tage)
I have a yearly timetable (events(1X365)) and I want to find how many consecutive values are equal to 1 for every month. Right now the below code calculates the consecutive ones (1) for January:
f= find(diff([0; (events{1,1}); 0]==1));
events_Jan= [f(1:2:end-1) f(2:2:end)-1 (f(2:2:end)-1-(f(1:2:end-1))+1)];
Max_conseq_for_January=max(events_Jan(:,3));
How can I create a loop for all the 12 months?

Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 12 Dez. 2022
hello
well a simple for loop will do the job
your result in now an array of length 12 : Max_conseq
load('events.mat')
for m =1:numel(events) % loop over month
f= find(diff([0; events{m} ; 0]==1));
events_this_month= [f(1:2:end-1) f(2:2:end)-1 (f(2:2:end)-1-(f(1:2:end-1))+1)];
Max_conseq(m) = max(events_this_month(:,3));
end
  4 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements 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!

Translated by