Clear Filters
Clear Filters

cell2table not working!

4 views (last 30 days)
Sonali
Sonali on 4 May 2024
Commented: Walter Roberson on 6 May 2024
Hello, I am trying to open a cdf file and save it in a table. I have used cell2table to do that but it just give me the table of cells as shown below in output. I need to read the contents of it. I was wondering if I could get somehelp with this. Thanks
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 = spdfcdfinfo(list).Variables(:,1);
data{j} = cell2table(spdfcdfread(list), 'VariableNames', vars);
end
Output:
data = 1×79 table epochtime_mettime_ephemeristime_unixtime_starttime_endtime_deltatime_integeprom_verheadervalidmoderateswp_indmlut_indeff_indatt_indsc_potmagfquat_scquat_msobins_scpos_sc_msobkgdeaddataefluxquality_flagproject_namespacecraft1
21600×1 double21600×1 double21600×1 double21600×1 double21600×1 double21600×1 double21600×1 double21600×1 double21600×1 int1621600×1 int3221600×1 int1621600×1 int1621600×1 int1621600×1 int1621600×1 int1621600×1 int1621600×1 int1621600×1 single21600×3 single21600×4 single21600×4 single21600×1 int1621600×3 single2×64×21600 single2×64×21600 single2×64×21600 single2×64×21600 single21600×1 int16'MAVEN''0'
  4 Comments
Walter Roberson
Walter Roberson on 4 May 2024
spdfcdfread() is from github, including from irfu-matlab/contrib/nasa_cdf_patch

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 4 May 2024
The first 18 results of spdfcdfread() are 21600 x 1 (of various numeric data types)
Then you have a 21600x3 followed by two 21600x4, then a 21600x1 and a 21600x3
After that you have four 2 x 64 x 21600 .
The 21600 x various sizes could concievably be converted into table variables together, but the 2 x 64 x 21600 would need to be reshaped to fit the 21600 x * sizing.
After that you have a big mix of sizes, including character vectors such as 'MAVEN', including numeric scalars, including a series of 64×27×2 single, including 64×9×2 single, including 4×8 char ...
With all those different sizes, you cannot convert to a table.
You will need to assign to a temporary variable, and extract portions of the temporary variable for conversion (possibly reshaping them and splitting them into cells.)
  4 Comments
Sonali
Sonali on 5 May 2024
I just wanted data in a table. struct2table is nt working.
Walter Roberson
Walter Roberson on 6 May 2024
temp = cellfun(@(C) {C}, spdfcdfread(list));
data{j} = table(temp{:}, 'VariableNames', vars);

Sign in to comment.

Categories

Find more on Tables 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!