How to label the points on x axis in hours.

19 ビュー (過去 30 日間)
Vikash Raj
Vikash Raj 2022 年 1 月 31 日
コメント済み: Vikash Raj 2022 年 2 月 13 日
Hi
I have a satellite timetsamp data in the form of '2016-02-05T01:01:24Z' I have used the matlab codes to remove T, Z and time in hours. I want to plot several days data according to time in hours with interval of 2 hrs. When I'm using the simple plot application, the axis is showing the time in days. Im intresetd to get the x axis in hours since the data also have Time in hours. How can I do this. My codes are
% Remove T and Z and time in HH:mm:ss from timestamp
TM1 = strrep(Timestamp, 'T', ' ');
TM2 = strrep(TM1, 'Z', ' ');
TmF = datetime(TM2, 'InputFormat','yyyy-MM-dd HH:mm:ss', 'Format','HH:mm:ss');
% Plot graph
plot(TmF,VTEC)
Im also attaching the simple plot which shows x axis in days.

回答 (3 件)

Star Strider
Star Strider 2022 年 1 月 31 日
Use this approach to convert the strings to datetime arrays:
old = {'2020-08-03T20:40:00.111Z'; '2020-08-03T21:40:01.123Z'};
time = datetime(old, 'InputFormat','yyyy-MM-dd''T''HH:mm:ss.SSS''Z''', 'TimeZone','UTC', 'Format','yyyy-MMM-dd HH:mm:ss.SSS')
time = 2×1 datetime array
2020-Aug-03 20:40:00.111 2020-Aug-03 21:40:01.123
time_in_hours = hour(time)
time_in_hours = 2×1
20 21
Then, plot the data against ‘time_in_hours’.
.
  2 件のコメント
Vikash Raj
Vikash Raj 2022 年 2 月 1 日
The time that I obtained using the above codes rounds the time to whole values example 20:40:00.111 to 20.I need the time as it is. How can I do that.
Star Strider
Star Strider 2022 年 2 月 1 日

サインインしてコメントする。


Cris LaPierre
Cris LaPierre 2022 年 1 月 31 日
First, you don't have to remove the T and Z. Just use the proper InputFormat for your timestamp
t='2016-02-05T01:01:24Z';
T = datetime(t,'InputFormat','yyyy-MM-dd''T''HH:mm:ss''Z')
T = datetime
05-Feb-2016 01:01:24
Once you have your times, just plot the data with datetimes on X. Then use xtickformat to set the display format to hours.
plot(T,5,'x')
xtickformat('HH')
If you don't want the date at all, consider using the timeofday function.
figure
plot(timeofday(T),5,'x')
xtickformat('h')

Vikash Raj
Vikash Raj 2022 年 2 月 10 日
編集済み: Vikash Raj 2022 年 2 月 10 日
Hi Thank you for the codes. This codes are not working in R2021 matlab program. When I run this codes it is giving error.
  6 件のコメント
Cris LaPierre
Cris LaPierre 2022 年 2 月 11 日
Please attach your data file to your post using the paperclip icon.
Vikash Raj
Vikash Raj 2022 年 2 月 13 日
Hi
Please find the sample data attached.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by