Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Tell me when count of occurrences in a rolling 7-day range exceeds a certain value.
1 回表示 (過去 30 日間)
古いコメントを表示
Say I have a column of dates and a column of ON and OFF representing the two states of a switch
5/16/2019 ON
5/16/2019 OFF
5/16/2019 ON
5/14/2019 OFF
5/13/2019 ON
5/13/2019 OFF
etc..
If I wanted to write a script that would tell me when the switch was OFF 4 times or more within ANY 7-day period (rolling period) how exactly would I go about that? It seems like it would be pretty simple but I'm not a good programmer whatsoever.
Thank you.
0 件のコメント
回答 (1 件)
KSSV
2019 年 5 月 17 日
T = readtable('data.txt') ;
S = T.(2) ;
on = contains(S,'ON') ;
off = contains(S,'OFF') ;
% Count ON
A = on' ;
ii = zeros(size(A));
jj = A > 0;
ii(strfind([0,jj(:)'],[0 1])) = 1;
idx = cumsum(ii).*jj;
out = accumarray( idx(jj)',A(jj)',[],@(x){x'});
thesum_on = cellfun(@sum,out)
% Count OFF
A = off' ;
ii = zeros(size(A));
jj = A > 0;
ii(strfind([0,jj(:)'],[0 1])) = 1;
idx = cumsum(ii).*jj;
out = accumarray( idx(jj)',A(jj)',[],@(x){x'});
thesum_off = cellfun(@sum,out)
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!