Sorting time in 1 hour time slots.
1 回表示 (過去 30 日間)
古いコメントを表示
I have a column matrix in datetime format, specifying time. I want to count the frequency of these time in 1hour time slots, that I have defined in a 24 x 2 matrix (datetime format). I tried using 'isbetween', but it gives only 0 as ouput.
For eg. :
A = [06:36:00 ; 09:45:23 ; .............. ; 15:17:07]; %Column matrix with time.
B = [00:00:00 , 01:00:00 , 02:00:00 , 03:00:00 , .................... , 23:00:00;
01:00:00 , 02:00:00 , 03:00:00 , 04:00:00 , .................... , 00:00:00;] % time slots. First column is start time and second column is end time.
Output should be a 24 x 1 matrix, with frequency for each time slot.
output = [0 0 0 12 6 ................. 2];
Kinldy help.
0 件のコメント
回答 (3 件)
Star Strider
2020 年 11 月 25 日
One approach:
A = datetime([zeros(100,4) randi(1440, 100, 1) zeros(100,1)]); % Create Data
[H,~,ix] = unique(hour(A)); % Unique Hours
Output = accumarray(ix, 1); % Tally
.
0 件のコメント
Steven Lord
2020 年 11 月 25 日
編集済み: Steven Lord
2020 年 11 月 25 日
minutesPerDay = minutes(days(1));
m = minutes(randi(minutesPerDay, 100, 1));
n = datetime('now');
t = n + m;
h = histogram(t, 'BinWidth', hours(1));
tickloc = dateshift(n, 'start', 'hour') + hours(0:6:24);
tickloc.Format = 'HH';
xticks(tickloc)
The tick label formatting isn't perfect, but I believe that's partly because this figure is smaller than the figure you would create in a desktop MATLAB session. If you just need the binning information use histcounts or discretize instead of histogram.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!