How to create a date starting from a specific date and time line for x axis

조회 수: 3 (최근 30일)
Dushan Sandaruwan
Dushan Sandaruwan 2021년 3월 2일
편집: Samayochita 2025년 2월 12일
I have a data set for temperature staring from 2/6/2021 7:12 a.m .
I need to create a x axis with a date starting from 2/6/2021 7:12 a.m to 2/7/2021 1:31 pm. with one minute changes. size of the date line should be 1100
this x axis only need to show the time
and then I need to plot this x axis aginst my temperature labeling with 6 hour intervals.

답변 (1개)

Samayochita
Samayochita 2025년 2월 12일
편집: Samayochita 2025년 2월 12일
Hi Dushan,
I see that you are trying to create a time-based x-axis starting from a specific date and time (like 2/6/2021 7:12 AM), having one-minute intervals. I suggest you try to implement the following:
Below is an example code I wrote for your reference:
% Define start and end date:
startDate = datetime(2021, 2, 6, 7, 12, 0);
endDate = datetime(2021, 2, 7, 13, 31, 0);
% Create a date range with 1-minute intervals
timeRange = startDate:minutes(1):endDate;
% Format the X-axis to show time only (without the full date)
datetick('x', 'HH:MM', 'keeplimits');
% Label the X-axis with 6-hour intervals
xticks(startDate:hours(6):endDate);
xticklabels(datestr(startDate:hours(6):endDate, 'HH:MM'));
Hope this helps!

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by