Azzera filtri
Azzera filtri

The setting of the time series on the x-axis

3 visualizzazioni (ultimi 30 giorni)
peter huang
peter huang il 17 Mag 2022
Risposto: Voss il 29 Mag 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

Risposte (1)

Voss
Voss il 29 Mag 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')

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by