How to change datenum to normal date format?

7 ビュー (過去 30 日間)
UTKARSH VERMA
UTKARSH VERMA 2021 年 2 月 16 日
コメント済み: UTKARSH VERMA 2021 年 3 月 9 日
Hi all,
I have tried using following command but as a result date has wrong year and they are not in sequence too:
datestr(A{1})
>>'01-Jul-4447'
'25-Jul-4447'
'18-Aug-4447'
'11-Sep-4447'
'05-Oct-4447'
'29-Oct-4447'
datetime(A{1}, 'ConvertFrom', 'datenum', 'Format', 'dd-MM-yyyy')
>>01-07-4447
25-07-4447
18-08-4447
11-09-4447
05-10-4447
29-10-4447
datevec(A{1})
>>4447 7 1 0 0 0
4447 7 25 0 0 0
4447 8 18 0 0 0
4447 9 11 0 0 0
4447 10 5 0 0 0
4447 10 29 0 0 0
I have attached a dummy data here in this link:

回答 (2 件)

Walter Roberson
Walter Roberson 2021 年 2 月 26 日
filename = 'olr_1985.nc';
times = hours(ncread(filename, 'time')) + datetime(1800,1,1, 'format', 'yyyy-MM-dd hh:mm');
Results are 1985-01-01 12:00 to 1985-04-30 12:00
  1 件のコメント
UTKARSH VERMA
UTKARSH VERMA 2021 年 3 月 9 日
Hi Walter,
I tried above code but the results are different to what you have mentioned:
'1806-03-03 08:30'
'1806-03-03 09:30'
'1806-03-03 10:30'
'1806-03-03 11:30'
'1806-03-03 12:30'

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


ANKUR KUMAR
ANKUR KUMAR 2021 年 2 月 26 日
You can use this function from the matlab file exchange to read time from a ncetcf file in user specified format: https://in.mathworks.com/matlabcentral/fileexchange/87894-ncreadtime
An example is shown below using the file you attached:
file='olr_1985.nc'
ncreadtime(ncread(file,'time'),ncreadatt(file,'time','units'),'yyyymmdd_HH')
  1 件のコメント
UTKARSH VERMA
UTKARSH VERMA 2021 年 2 月 28 日
Thanks, I tried it worked fine!

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

カテゴリ

Help Center および File ExchangeTime Series Objects についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by