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')

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by