find frequency and duration of numerical events in a matrix

2 ビュー (過去 30 日間)
elisabetta fedeli
elisabetta fedeli 2019 年 3 月 5 日
編集済み: Andrei Bobrov 2019 年 3 月 7 日
I have a matrix where the rows are minutes of a day (starting from 0:00 and ending at 23:59) and the columns are different days (over 1000 days). The numerical values in the matrix are events that occur over several minutes in a day so they are groups of values that extend over some rows in the same column surrounder by zeros. I would like to know, for every hour (es from 0:00 to 1:00) the mean value of the number of events that occurred and their mean duration in minutes.
  4 件のコメント
dpb
dpb 2019 年 3 月 5 日
OK, so we are clear on the definition of "event'...for the first column
2.50
0.00
0.29 -- begin?
0.50 or --begin?
0.50
0.50
0.50
0.22 -- end?
0.00 -- end??
0.00
...
is the event the any stretch of nonzero values or the stretch of equi-valued values?
Is the duration of the even inclusive/exclusive of the start/stop markers on one/both/either end?
elisabetta fedeli
elisabetta fedeli 2019 年 3 月 6 日
Thank you for the reply, the event is any stretch of nonzero values.
2.50 -- begin and end (duration 1 minute)
0.00
0.29 -- begin
0.50
0.50
0.50
0.50
0.22 -- end (duration 6 minutes)
0.00
0.00
...
It would also be ideal if I could consider an event overlapping 2 hours a fraction of an event. Like this:
2.50 -- begin and end (duration 1 minute)
0.00
0.29 -- begin
0.50 --- end (the event is considered 2/6 of an event, duration 2 minutes)
----------- end of the first hour (every hour is composed of 60 rows)
0.50 --- begin
0.50
0.50
0.22 -- end (the event is considered 4/6 of an event, duration 4 minutes)
0.00
0.00
...

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 3 月 6 日
編集済み: Andrei Bobrov 2019 年 3 月 7 日
Let A - your array (1440 x Days):
k = 60;% k = 60 (minuties in hour)
[m,n] = size(A);
a1 = A ~= 0;
A1 = diff([false(1,n);a1]) == 1;
[ii,iii] = ndgrid(1:k,1:m/k);
A1(ii(:) == 1 & a1) = true;
data = cumsum(A1).*double(a1);
T = array2table([iii(:),data],'V',[{'Time'},sprintfc('DAY%d',1:n)]);
out = varfun(@fun,T,'InputVariables',2:n+1,'GroupingVariables',1);
out = out(:,[1,3:end]);
out.Properties.VariableNames{1} = 'Hour';
Here fun is m-file fun.m:
function y = fun(x)
[~,~,c] = unique(x(x > 0));
y = [max(c), mean(accumarray(c,1))];
end
  2 件のコメント
elisabetta fedeli
elisabetta fedeli 2019 年 3 月 6 日
Thank you very much! It works but i'm not sure it serves my purpose or maybe I just don't understand the script. I'm very new to matlab and i understand that every element in a column of the out matrix is an event and it's value is it's duration. Is it possible to group the results by hour? To have an out matrix 24 x n.days so that if in an hour there's no event the value for that hour is zero?
Andrei Bobrov
Andrei Bobrov 2019 年 3 月 6 日
I'm fixed my answer.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHistorical Contests についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by