Load time from netcdf file and retain the 'Hour' value

13 ビュー (過去 30 日間)
mashtine
mashtine 2015 年 6 月 22 日
回答済み: shankar sharma 2022 年 1 月 21 日
Hello,
I have a time variable (attached) that I created from using
netcdf_time = ncread('sample.netcdf','time');
When I use ncdisp on the netcdf file, time is described as the following:
time
Size: 102272x1
Dimensions: time
Datatype: int32
Attributes:
units = 'hours since 1900-01-01 00:00:0.0'
long_name = 'time'
calendar = 'gregorian'
My question is, what do I do with the netcdf_time variable to get the time into matlab datenum format while retaining the 'hour'. I have used this based on online phishing
time = double(netcdf_time/24 + datenum('1900-01-01 00:00:00'));
But, datestr(time(1:7,1),'dd-mm-yyyy HH:MM:SS') returns
01-01-1980 00:00:00
01-01-1980 00:00:00
01-01-1980 00:00:00
02-01-1980 00:00:00
02-01-1980 00:00:00
02-01-1980 00:00:00
02-01-1980 00:00:00
When it should return
01-01-1980 03:00:00
01-01-1980 06:00:00
01-01-1980 09:00:00
01-01-1980 12:00:00
01-01-1980 15:00:00
01-01-1980 18:00:00
01-01-1980 21:00:00
Any ideas?

採用された回答

Ashish Uthama
Ashish Uthama 2015 年 6 月 22 日
Instead of
time = double(netcdf_time/24 + datenum('1900-01-01 00:00:00'));
(netcdf/24 is still happening in int32, hence you are loosing precision)
Try
time = double(netcdf_time)/24 + datenum('1900-01-01 00:00:00');
  3 件のコメント
suchitra rani
suchitra rani 2019 年 8 月 24 日
Helpful.
Werner Barros
Werner Barros 2020 年 8 月 20 日
Ashish Uthama thanks alot

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

その他の回答 (3 件)

Werner Barros
Werner Barros 2019 年 10 月 24 日
You can try to:
xxx = datevec(VARIABLE);

Werner Barros
Werner Barros 2020 年 7 月 29 日
Thanks for help :D

shankar sharma
shankar sharma 2022 年 1 月 21 日
time1=double(netcdf_time)/24+datenum('1900-01-01 00:00:00');
final_time=datevec(time1);

カテゴリ

Help Center および File ExchangeNetCDF についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by