Changing x-axis scale for hours

Hello I have hourly data from 1 week (168 hours) I would like to have the x-axis scale to be 1...24 1...24 etc instead of 1....168
How could this be achieved?
Thanks in advance!

回答 (1 件)

Cris LaPierre
Cris LaPierre 2023 年 6 月 8 日

0 投票

For that to work, you would need to convert your x data to a datetime array, where there is a date associated with each time. Then you could have the axis display the hours. Maybe something like this?
x = 1:5:40;
y = rand(size(x));
startDate = datetime(2020,02,01,0,0,0)
startDate = datetime
01-Feb-2020
x = startDate + hours(x)
x = 1×8 datetime array
01-Feb-2020 01:00:00 01-Feb-2020 06:00:00 01-Feb-2020 11:00:00 01-Feb-2020 16:00:00 01-Feb-2020 21:00:00 02-Feb-2020 02:00:00 02-Feb-2020 07:00:00 02-Feb-2020 12:00:00
plot(x,y)
xtickformat('HH');

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

製品

リリース

R2022b

タグ

質問済み:

2023 年 6 月 8 日

回答済み:

2023 年 6 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by