Represent CDF Time Values
This example shows how to extract date and time information from CDF datasets. CDF has three data types that represent date and time values, each of which can be represented in MATLAB®:
CDF_TIME_TT2000data measures the number of nanoseconds elapsed since 01-Jan-2000 at 12:00:00 Terrestrial Time (TT).CDF_TIME_TT2000data can be represented in MATLAB asdatetimeorint64values.CDF_EPOCHdata measures the number of milliseconds elapsed since 01-Jan-0000.CDF_EPOCHdata can be represented in MATLAB asdatetimeordoublevalues.CDF_EPOCH16data measures the number of picoseconds elapsed since 01-Jan-0000.CDF_EPOCH16data can be represented in MATLAB asdoublevalues.
Represent CDF Time Values as int64 or double Values
Read the tt2000 (of type CDF_TIME_TT2000) and Time (of type CDF_EPOCH) variables from the sample CDF file example_364.cdf. Set the DatetimeType name-value argument to "native". cdfread returns a cell array.
data_native = cdfread("example_364.cdf","Variables",{"tt2000","Time"}, ... "DatetimeType","native"); whos data_native
Name Size Bytes Class Attributes data_native 24x2 6144 cell
Save the two CDF variables as MATLAB vectors and examine the output. The variable with CDF_TIME_TT2000 data has type int64, while the variable with CDF_EPOCH data has type double.
cdf_time_tt2000_data_native = [data_native{:,1}];
cdf_epoch_data_native = [data_native{:,2}];
whos cdf*_nativeName Size Bytes Class Attributes cdf_epoch_data_native 1x24 192 double cdf_time_tt2000_data_native 1x24 192 int64
cdf_time_tt2000_data_native(1:3)'
ans = 3×1 int64 column vector
536500865284200300
536500866284200300
536500867284200300
cdf_epoch_data_native(1:3)'
ans = 3×1
1013 ×
6.3146
6.3146
6.3146
Represent CDF Time Values as datetime Values
Read the same two CDF variables again. This time, set the DatetimeType name-value argument to "datetime".
data_datetime = cdfread("example_364.cdf","Variables",{"tt2000","Time"}, ... "DatetimeType","datetime"); whos data_datetime
Name Size Bytes Class Attributes data_datetime 24x2 9664 cell
Again save the two CDF variables as MATLAB vectors and examine the output. Both variables have type datetime.
cdf_time_tt2000_data_datetime = [data_datetime{:,1}];
cdf_epoch_data_datetime = [data_datetime{:,2}];
whos cdf*_datetimeName Size Bytes Class Attributes cdf_epoch_data_datetime 1x24 240 datetime cdf_time_tt2000_data_datetime 1x24 480 datetime
cdf_time_tt2000_data_datetime(1:3)'
ans = 3×1 datetime
2016-12-31T23:59:57.100200300Z
2016-12-31T23:59:58.100200300Z
2016-12-31T23:59:59.100200300Z
cdf_epoch_data_datetime(1:3)'
ans = 3×1 datetime
01-Jan-2001 00:00:00.000
01-Jan-2001 01:00:00.000
01-Jan-2001 02:00:00.000