how to convert string to a daily datetime?

26 ビュー (過去 30 日間)
sherien fadhel
sherien fadhel 2024 年 11 月 12 日 19:39
コメント済み: Steven Lord 2024 年 11 月 12 日 20:19
I extracted the time array from (nc file), its a daily time arry for the year 1979, and below is sample of the extracted data.
The description of the nc file gave the following below details.
Can any one help me to convert the string numbers to the a datetime arry ?
Sample of the data
Time=[ 692496 692520 692544 692568 692592 692616 692640 692664 692688 692712 692736 692760 692784 692808 692832 692856 692880 692904 692928 692952 692976 693000 693024 693048 693072 693096 693120 693144 693168 693192 693216 693240 693264 693288 693312 693336 693360 693384 693408 693432 693456 693480 693504 693528 693552 693576 693600 693624 693648 693672 693696 693720 693744 693768 693792 693816 693840 693864 693888 693912 ]
Description of nc file about the time array
time
Size: 365x1
Dimensions: time
Datatype: double
Attributes:
long_name = 'Time'
axis = 'T'
standard_name = 'time'
coordinate_defines = 'start'
actual_range = [692496 701232]
delta_t = '0000-00-01 00:00:00'
avg_period = '0000-00-01 00:00:00'
units = 'hours since 1900-01-01 00:00:00'

採用された回答

Walter Roberson
Walter Roberson 2024 年 11 月 12 日 19:56
DateTime = datetime('1900-01-01 00:00:00') + Time/24;
  2 件のコメント
sherien fadhel
sherien fadhel 2024 年 11 月 12 日 20:06
it works well, thanks alot
Steven Lord
Steven Lord 2024 年 11 月 12 日 20:19
Or taking advantage of the units description to make the code look closer to that description:
Time=[ 692496 692520 692544 692568 692592 692616 692640 692664 692688 692712 692736 692760 692784 692808 692832 692856 692880 692904 692928 692952 692976 693000 693024 693048 693072 693096 693120 693144 693168 693192 693216 693240 693264 693288 693312 693336 693360 693384 693408 693432 693456 693480 693504 693528 693552 693576 693600 693624 693648 693672 693696 693720 693744 693768 693792 693816 693840 693864 693888 693912 ];
dt1 = hours(Time) + datetime(1900, 01, 01); % 'hours since 1900-01-01 00:00:00'
dt2 = datetime('1900-01-01 00:00:00') + Time/24;
isequal(dt1, dt2)
ans = logical
1

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by