Sorting time in 1 hour time slots.

3 次查看(过去 30 天)
vidit kedia
vidit kedia 2020-11-25
编辑: Steven Lord 2020-11-25
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.

回答(3 个)

Sean de Wolski
Sean de Wolski 2020-11-25
Look at retime.
doc retime

Star Strider
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
.

Steven Lord
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.

类别

Help CenterFile Exchange 中查找有关 Time Series Events 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by