Histogram with time data

10 ビュー (過去 30 日間)
Michael Molini
Michael Molini 2019 年 7 月 11 日
回答済み: Dheeraj Singh 2019 年 7 月 17 日
I have to create a histogram showing the frequency of wake up times. For example my Data consists of 21 various wake up times ranging from 7AM to 12:30PM. However My data for time is in decimal format. For example, waketime is 7.25 instead of 7:15 AM. I want to change the x axis to display the correct time in HH:MM AM.
  1 件のコメント
KSSV
KSSV 2019 年 7 月 11 日
Have a look on xticks

サインインしてコメントする。

回答 (1 件)

Dheeraj Singh
Dheeraj Singh 2019 年 7 月 17 日
Hi,
You can use the xticks and xticklabels to plot the frequency histogram.
The following code below implements the above required functionality
%wakeup data
x=[7 7.25 8.25 9 10.5 11 7.25 9.15 9.25 10.15 12]
%define no of bins
noOfBins=min(x):0.25:max(x);
%plot histogram
histogram(x,numel(noOfBins));
timeFormat=noOfBins;
timeFormat=timeFormat/24;
la=datestr(timeFormat,'HH:MM')
xticks(noOfBins);
xticklabels({la});
The following figure below shows example output of the histogram
histogram.png

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by