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