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 Center および File ExchangeDates and Time についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by