Hello guys!
I was trying to plot a datetime arrangement (vector) in a 12-hour histogram.
The problem is that when I try to plot it, it considers the whole date (since each element has a dd-MM-yy HH:mm:ss format), so I was wondering if is possible to isolate the hour in order to get an histogram that shows the hourly frecuency in a single day (only considering the hour). Another option I was considering is transforming the HH element into another data type easier to plot, but once again, I am not sure how to do it.
Thank you in advance,
Carlos.

 채택된 답변

Star Strider
Star Strider 2020년 12월 30일

1 개 추천

I am not certain what your data are or the actual result you want.
Try this:
DT = datetime('now')+hours(0:72).'; % Create ‘datetime’ Array
T1 = table(DT, rand(size(DT))); % Create Table With Data
[UCol1,~,ix] = unique(mod(hour(T1{:,1}),12)); % Unique Values & Indices
Tally = accumarray(ix, T1{:,2}); % Counts
figure
bar(UCol1, Tally)
grid
.

댓글 수: 2

Carlos Armas
Carlos Armas 2020년 12월 30일
Thank you! it completely solved my problem.
Star Strider
Star Strider 2020년 12월 30일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Steven Lord
Steven Lord 2020년 12월 30일
rightNow = datetime('now')
rightNow = datetime
30-Dec-2020 19:10:28
howLongSinceMidnight = timeofday(rightNow)
howLongSinceMidnight = duration
19:10:28

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

2020년 12월 30일

답변:

2020년 12월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by