merge two datetime arrays into one datetime arrays

30 ビュー (過去 30 日間)
근영 박
근영 박 2022 年 2 月 22 日
コメント済み: 근영 박 2022 年 2 月 22 日
Time =
15×1 datetime array
19:20:03
19:20:13
19:20:23
19:20:33
19:20:43
19:20:53
19:21:02
19:21:12
19:21:22
19:21:32
19:21:42
19:21:52
19:22:02
19:22:12
19:22:22
date =
15×1 datetime array
2022-02-01
2022-02-01
2022-02-01
2022-02-01
2022-02-01
2022-02-01
2022-02-01
2022-02-01
2022-02-01
2022-02-01
2022-02-01
2022-02-01
2022-02-01
2022-02-01
2022-02-01
dt =
15×1 datetime array
2022-02-01 19:20:03
2022-02-01 19:20:13
2022-02-01 19:20:23
2022-02-01 19:20:33
2022-02-01 19:20:43
2022-02-01 19:20:53
2022-02-01 19:21:02
2022-02-01 19:21:12
2022-02-01 19:21:22
2022-02-01 19:21:32
2022-02-01 19:21:42
2022-02-01 19:21:52
2022-02-01 19:22:02
2022-02-01 19:22:12
2022-02-01 19:22:22
I want to make "dt" with "TIme", "date".

採用された回答

Cris LaPierre
Cris LaPierre 2022 年 2 月 22 日
編集済み: Cris LaPierre 2022 年 2 月 22 日
Before you merge, you need to know that all datetime arrays have a date and time associated with them, even if that information is not displayed due to the formatting applied.
d = datetime('today')
d = datetime
22-Feb-2022
d.Format = 'HH:mm:ss'
d = datetime
00:00:00
The point, then, is to first check your format to make sure the information is not already there. If there truly is no date information associated with the time data, then it is best to import this data as a duration instead of a datetime.
As a duration, you could then just add the date and time together.
a = datetime('today')
a = datetime
22-Feb-2022
t = duration(19,20,3)
t = duration
19:20:03
dt = a+t
dt = datetime
22-Feb-2022 19:20:03
However, if your time is a datetime, you must extract just the time of day before adding it to your date.
f = datetime('today')
f = datetime
22-Feb-2022
g = datetime('now','Format','HH:mm:ss')
g = datetime
14:03:09
Y = f+timeofday(g)
Y = datetime
22-Feb-2022 14:03:09
  1 件のコメント
근영 박
근영 박 2022 年 2 月 22 日
Thank you so much.

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

その他の回答 (1 件)

HWIK
HWIK 2022 年 2 月 22 日
There might be something more efficient but this should work:
dt = datetime(strcat(string(date')," ",string(time')))
  1 件のコメント
근영 박
근영 박 2022 年 2 月 22 日
Thank you for answer.

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

カテゴリ

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