The setting of the time series on the x-axis

4 次查看(过去 30 天)
I have data that is hourly and up to five years. In the time part, I use datenum to convert it into a number so that I can plot a graph related to the data and time, but I am the value of datenum in xlabel. I would like to ask if there is a method in matlab. The way the xlabel renders become normal time ex : Data length 2000 01-2005 12 Display the x-axis year by year in the xlabel

回答(1 个)

Voss
Voss 2022-5-29
Instead of using datenum x values, you can plot with datetime x values and then set the xticklabel format using xtickformat:
% some datenum values:
x = [7.35e5 7.36e5 7.37e5];
% convert datenum to datetime (it's likely you can bypass this conversion
% and use datetime() on your data directly)
x = datetime(x,'ConvertFrom','datenum')
x = 1×3 datetime array
11-May-2012 05-Feb-2015 01-Nov-2017
% plot with datetimes:
plot(x,[3 2 4])
% set the xtick format:
% xtickformat('yyyy-MM') % take your pick
xtickformat('yyyy')

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by