フィルターのクリア

count the number of hours in a day (multiple values per hour)

2 ビュー (過去 30 日間)
pavlos
pavlos 2017 年 5 月 19 日
回答済み: Sean de Wolski 2017 年 5 月 19 日
Hello,
Please help me with the following.
Consider a matrix
M= [ 0 0 1 2 2 2 2 3 3 ... 23 0 1 1 2 2 2 3 3 3 3 ... 23 ];
These values corresponds to hours and my real matrix reaches up to 23.
I need to find per day how many values per hours existing. For example, the 1st day has two 0, one 1, three 2, two 3, etc, up to 23. The 2nd day has one 0, two 1, etc.
Thank you very much.
Best,
Pavlos

採用された回答

Sean de Wolski
Sean de Wolski 2017 年 5 月 19 日
M = [0 0 1 2 2 2 2 3 3 23 0 1 1 2 2 2 3 3 3 3 23];
M = M(:); % columns are better
daybreaks = sign([diff(M); -5])==-1; % where do days split?
dayidx = repelem((1:sum(daybreaks)).',diff([0; find(daybreaks)]),1); % Which day
[mhour, ~, houridx] = unique(M); % unique hours
RecordsBYDay = accumarray([houridx, dayidx],1); % number of records for hour/day
table(mhour,RecordsBYDay)

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by