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

3 次查看(过去 30 天)
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