フィルターのクリア

time date to datenum and datenum to datetime

67 ビュー (過去 30 日間)
Ismita
Ismita 2022 年 4 月 26 日
回答済み: Corey Silva 2022 年 5 月 18 日
I have time in 'yyyy-MM-dd''T''HH:mm:ss.SSS''Z' formate (e.g., [2018-08-01T20:05:00.000Z; 2018-08-01T20:10:00.000Z; 2018-08-01T20:35:00.000Z; 2018-08-01T25:05:00.000Z] . How to make time string and datetime to datenum and datenum to datetime?
Thanks in advance.
(I am new in matlab.)
  5 件のコメント
Stephen23
Stephen23 2022 年 4 月 26 日
編集済み: Stephen23 2022 年 4 月 26 日
"But I need it serially here"
What is the exact operation that requires a serial date number?
Both DATETIME and DURATION objects support many many methods and functions, if you actually explained how you are going to process your data then we could help you use a better approach.
Ismita
Ismita 2022 年 4 月 26 日
Thank you. You can check the data attached in the comment threading.

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

採用された回答

Bruno Luong
Bruno Luong 2022 年 4 月 26 日
編集済み: Bruno Luong 2022 年 4 月 26 日
I make a round conversion so you can convert any format to any other by using the appropriate substeps
dt=datetime(2022,04,28,13,09,00,'Format','yyyy-MM-dd''T''HH:mm:ss.SSS''Z''')
dt = datetime
2022-04-28T13:09:00.000Z
dn=datenum(dt)
dn = 7.3864e+05
ds = datestr(dn)
ds = '28-Apr-2022 13:09:00'
dt = datetime(ds,'InputFormat','dd-MMM-yyyy HH:mm:SS','Format','yyyy-MM-dd''T''HH:mm:ss.SSS''Z''')
dt = datetime
2022-04-28T13:09:00.000Z
  11 件のコメント
Bruno Luong
Bruno Luong 2022 年 4 月 26 日
編集済み: Bruno Luong 2022 年 4 月 26 日
They are table, if you aceess them by column name, it returns the standard column-vector of doubles
s.Var2 + s.Var3
Ismita
Ismita 2022 年 4 月 26 日
thanks a lot.

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

その他の回答 (2 件)

Steven Lord
Steven Lord 2022 年 4 月 26 日
I'm going to assume that you've imported this data into MATLAB as a string array or a cellstr with two columns. Since I don't have the file or whatever other source this data comes from, I'll hard code it so my example can operate on it.
S = ["2008-01-01T00:00:00.000Z", "-1.06";
"2008-01-01T00:05:00.000Z", "-1";
"2008-01-01T00:10:00.000Z", "-1.76";
"2008-01-01T00:15:00.000Z", "-2.09"];
Let's create a datetime array using the first column of S.
fmt = 'yyyy-MM-dd''T''HH:mm:ss.SSS''Z''';
dt = datetime(S(:, 1), 'InputFormat', fmt, 'Format', fmt)
dt = 4×1 datetime array
2008-01-01T00:00:00.000Z 2008-01-01T00:05:00.000Z 2008-01-01T00:10:00.000Z 2008-01-01T00:15:00.000Z
Now to create a double array using the second column of S.
n = double(S(:, 2))
n = 4×1
-1.0600 -1.0000 -1.7600 -2.0900
Finally, storing this date and time data along with the numeric data in a timetable array would let us perform future operations on the data easily.
T = timetable(dt, n)
T = 4×1 timetable
dt n ________________________ _____ 2008-01-01T00:00:00.000Z -1.06 2008-01-01T00:05:00.000Z -1 2008-01-01T00:10:00.000Z -1.76 2008-01-01T00:15:00.000Z -2.09
  1 件のコメント
Ismita
Ismita 2022 年 4 月 26 日
編集済み: Ismita 2022 年 4 月 26 日
Thank you so much. Could you please inform me the type of 'T=timetable(dt,n)' data is text/numeric?
Should I use 'double(n)' / 'table2array(n)' for other variables like 'n' here?

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


Corey Silva
Corey Silva 2022 年 5 月 18 日
While serial date numbers (datenum) can represent dates and times, it is recommended that you use datetime values to represent points in time, and durationor calendarDuration values to represent elapsed times.

カテゴリ

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