Make an Histogram with 24 bars

조회 수: 2 (최근 30일)
flashpode
flashpode 2021년 10월 19일
답변: Steven Lord 2021년 10월 19일
I have a variable of duration and I want to get an histogram where each bar (24 in total, for each hour) contains the total messages recieved at the same hour

답변 (2개)

Cris LaPierre
Cris LaPierre 2021년 10월 19일
Check out the documentation for histogram. You likely want to use one of these syntaxes.

Steven Lord
Steven Lord 2021년 10월 19일
The histogram function can operate on datetime and duration arrays. Here's an example using datetime; you should be able to adapt it to operate on a duration array.
midnight = datetime('today');
secondsPerDay = seconds(days(1));
s = seconds(randi(secondsPerDay, 1000, 1));
T = midnight + s;
T(1:10) % Show the first few elements of T to show they contain date and time information
ans = 10×1 datetime array
19-Oct-2021 23:42:45 19-Oct-2021 21:59:22 19-Oct-2021 16:31:34 19-Oct-2021 14:18:30 19-Oct-2021 18:25:32 19-Oct-2021 10:08:10 19-Oct-2021 02:45:47 19-Oct-2021 17:54:04 19-Oct-2021 11:18:35 19-Oct-2021 10:02:54
histogram(T, midnight + hours(0:24)) % 1 hour long bins

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by