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!