Matlab is mixing MONTH and DAY up

5 ビュー (過去 30 日間)
Louise Wilson
Louise Wilson 2021 年 3 月 18 日
コメント済み: Star Strider 2021 年 3 月 22 日
Hello, I have a datetime array where the format is dd/MM/yyyy, but when I used ymd(), Matlab tells me that day is month and month is day. Using format() just rearranges the date but retains the confusion between day and month.
How do I rectify this, how can I dictate to Matlab which is the month and which is the day?
[y,m,d]=ymd(gps.LOCALDATE(1))
y =
2021
m =
9 %this is actually the day
d = %this is actually the month
3
  2 件のコメント
Louise Wilson
Louise Wilson 2021 年 3 月 22 日
@Star Strider Sorry, I can't share the data because it is sensitive but I can give a subset.
Louise Wilson
Louise Wilson 2021 年 3 月 22 日
I think I need to specify the format of the LOCALDATE data as I read it in but not sure how to do that.

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

採用された回答

Star Strider
Star Strider 2021 年 3 月 22 日
編集済み: Star Strider 2021 年 3 月 22 日
Try this:
D = load('gps.mat');
gps = D.gps;
LOCALDATETIME = datetime(string(gps.LOCALDATE),'InputFormat','dd/MM/yyyy', 'Format','dd/MM/yyyy HH:mm:ss') + gps.LOCALTIME;
with:
First_5_Rows = LOCALDATETIME(1:5)
producing:
First_5_Rows =
5×1 datetime array
09/03/2021 08:42:31
09/03/2021 08:42:32
09/03/2021 08:42:34
09/03/2021 08:42:35
09/03/2021 08:42:36
Since ‘gps.LOCALDATE’ is already a datetime array, converting it first to a string variable allowed datetime to parse it correctly.
EDIT — Added explanation.
  2 件のコメント
Louise Wilson
Louise Wilson 2021 年 3 月 22 日
Yes this looks to work! Thank you!
Star Strider
Star Strider 2021 年 3 月 22 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by