opening a cdf file

23 views (last 30 days)
Sonali
Sonali on 16 Apr 2024 at 20:03
Commented: Sonali on 17 Apr 2024 at 14:24
Hello, I am trying to open a cdf file. I have a program which has opened some cdf files in past. But Im unable to open the new set.
prog:
files='D:\CDF\';
files = dir('mvn_*.cdf');
num_files = length(files);
data= cell(1, num_files);
nam=files.name;
for j = 1:numel(files)
list = fullfile(files(j).folder, files(j).name);
vars = cdfinfo(list).Variables(:,1);
data{j} = cell2table(cdfread(list), 'VariableNames', vars);
end
Will really appreciate a solution here. Thanks
  2 Comments
the cyclist
the cyclist on 16 Apr 2024 at 21:09
CDF can mean a few different things. For example, is it Common Data Format, or Computable Document Format, or something else?
Sonali
Sonali on 17 Apr 2024 at 13:26
common data format, here.

Sign in to comment.

Accepted Answer

Gyan Vaibhav
Gyan Vaibhav on 17 Apr 2024 at 9:56
Hi Sonali,
I understand from the code you have provided, that you want to read a Common Data Format (CDF) file. I tried running your program and everything seems alright, however the cdfread function throws an error.
As of R2021a, reading CDF files which use a few certain datatypes is not supported. However, you can use the spdfcdfread function present in the patch provided by NASA for reading the CDF files you have. This could be the possible reason, which has been mentioned here for a similar problem. https://www.mathworks.com/matlabcentral/answers/765971-how-to-access-cdf-file
Download the patch file, and extract it to a specified folder. Add that folder to matlab path using the addpath command. You can get the patch and detailed installation instructions from here: https://cdf.gsfc.nasa.gov/html/matlab_cdf_patch.html
Once you are done with that change "cdfread" in your function to "spdfcdfread" as shown below and it generates the expected "data" table.
data{j} = cell2table(spdfcdfread(list), 'VariableNames', vars);
Hope this resolves your query.
Thanks
Gyan
  1 Comment
Sonali
Sonali on 17 Apr 2024 at 14:24
Thanks Gyan. It worked.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!