Effacer les filtres
Effacer les filtres

How to change datenum to normal date format?

5 vues (au cours des 30 derniers jours)
UTKARSH VERMA
UTKARSH VERMA le 16 Fév 2021
Commenté : UTKARSH VERMA le 9 Mar 2021
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:

Réponses (2)

Walter Roberson
Walter Roberson le 26 Fév 2021
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 commentaire
UTKARSH VERMA
UTKARSH VERMA le 9 Mar 2021
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'

Connectez-vous pour commenter.


ANKUR KUMAR
ANKUR KUMAR le 26 Fév 2021
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 commentaire
UTKARSH VERMA
UTKARSH VERMA le 28 Fév 2021
Thanks, I tried it worked fine!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Time Series Objects dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by