How do separate plot into months?

9 ビュー (過去 30 日間)
Devon Von Lichtenstein
Devon Von Lichtenstein 2020 年 10 月 4 日
I have an array of 8760 numbers consisting of a data point for every hour of a year. Instead of having the x-axis separated by hours (1-8760), how can I change it to months?
Would creating a vairable for each month with the corresponding hours from the year and then combining all 12 plots work?

採用された回答

Sindar
Sindar 2020 年 10 月 4 日
probably easiest would be to create a datetime object:
% sample data
data = rand(1,8760);
% starting year/month/day of data
Y = 2020;
M = 1;
D = 1;
% hours of data
H = 1:8760;
t = datetime(Y,M,D,H,0,0);
% plot your data, formating x-axis in month names
plot(t,data,'DatetimeTickFormat','MMMM')
% make sure every month gets a tick
xticks(datetime(Y,1:12,0))
% angle ticks for readability
xtickangle(45)
  1 件のコメント
Devon Von Lichtenstein
Devon Von Lichtenstein 2020 年 10 月 7 日
Thank you! That was exactly it.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by