How to read a CDF File?

조회 수: 8 (최근 30일)
Nur Zawani Rosli
Nur Zawani Rosli 2023년 1월 27일
편집: Tushar Behera 2023년 1월 30일
I am trying to read a CDF file obtained from SWARM Satellite Data Access. I have been using this code:
data1 = cdfread('SW_OPER_MAGA_LR_1B_20140101T000000_20140101T235959_0602_MDR_MAG_LR.cdf', ...
'ConvertEpochToDatenum', true);
writecell(data1,'example.txt');
type example.txt
I was able to read the data but the date and time does not appear in the array. I need the time to obtain a specific time where the satellite is available for my research. Additionally, is there a way to only read a specific range of time only? Since the file is too long and it takes a long time to run the whole file.
Thank you :)

답변 (1개)

Tushar Behera
Tushar Behera 2023년 1월 30일
편집: Tushar Behera 2023년 1월 30일
Hi Nur,
I believe that you are trying to read from a ".cdf" file using the "cdfread" function. However, You are not able to find the date and time in the array.
The code you are using for reading the ".cdf" file is correct and the date and time is in the first column, However, it is in "datenum" format as you have set the "ConvertEpochToDatenum" option to "true".
Use the code below to convert "datenum" format to "datetime" format which will give you an array of date and time,
t = datetime(cell2mat(data1(:,1)),'ConvertFrom','datenum')
you can concatenate this array of datetime type data with your original cell type data. A better way to concatenate will be to convert this array to table format along with the cell type data you got from "cdfread". A table data type is best to use when working with different data types.
datetimedata=array2table(t);
originaldata=cell2table(data1);
newdata=[datetimedata originaldata];
Also you can specify range of data by indexing in to the table:
newdata(:,1);
This will give all the rows for the first column of the table. you can edit this code as per your requirements.
I hope this helps you in your work.
Regards,
Tushar

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by