Filter löschen
Filter löschen

The setting of the time series on the x-axis

3 Ansichten (letzte 30 Tage)
peter huang
peter huang am 17 Mai 2022
Beantwortet: Voss am 29 Mai 2022
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

Antworten (1)

Voss
Voss am 29 Mai 2022
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')

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by