cell2table not working!

1 次查看(过去 30 天)
Sonali
Sonali 2024-5-4
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 个评论
Walter Roberson
Walter Roberson 2024-5-4
spdfcdfread() is from github, including from irfu-matlab/contrib/nasa_cdf_patch

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2024-5-4
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 个评论
Sonali
Sonali 2024-5-5
I just wanted data in a table. struct2table is nt working.
Walter Roberson
Walter Roberson 2024-5-6
temp = cellfun(@(C) {C}, spdfcdfread(list));
data{j} = table(temp{:}, 'VariableNames', vars);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by