Calculate values from data to monthly

I have a timetable and I want to find how many values are equal to 1 for every class. Right now the code calculates the ones for beginning:
How can I create a loop for all the other classes?

 採用された回答

Mathieu NOE
Mathieu NOE 2022 年 12 月 12 日

0 投票

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

3 件のコメント

Mathieu NOE
Mathieu NOE 2022 年 12 月 12 日
oops
this should work better :
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)];
tmp = events_this_month(:,3);
if ~isempty(tmp)
Max_conseq(m) = max(tmp);
else
Max_conseq(m) = 0;
end
end
Ancalagon8
Ancalagon8 2022 年 12 月 13 日
Thanks a lot!
Mathieu NOE
Mathieu NOE 2022 年 12 月 13 日
My pleasure !

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2022 年 12 月 11 日

編集済み:

2025 年 1 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by