Effacer les filtres
Effacer les filtres

The setting of the time series on the x-axis

3 vues (au cours des 30 derniers jours)
peter huang
peter huang le 17 Mai 2022
Réponse apportée : Voss le 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

Réponses (1)

Voss
Voss le 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')

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by