필터 지우기
필터 지우기

The setting of the time series on the x-axis

조회 수: 3 (최근 30일)
peter huang
peter huang 2022년 5월 17일
답변: Voss 2022년 5월 29일
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