Sorting time in 1 hour time slots.
2 次查看(过去 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!