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

4 ビュー (過去 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 Center および File ExchangeAxis Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by