cell2table not working!
이전 댓글 표시
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
Matt J
2024년 5월 4일
Please make it possible for us to run the line,
cell2table(spdfcdfread(list), 'VariableNames', vars);
in isolation. In other words, attach the output of spdfcdfread(list) in a .mat file so we can see what it is and test how cell2table responds to it.
Sonali
2024년 5월 4일
Walter Roberson
2024년 5월 4일
spdfcdfread() is from github, including from irfu-matlab/contrib/nasa_cdf_patch
Sonali
2024년 5월 5일
답변 (1개)
Walter Roberson
2024년 5월 4일
0 개 추천
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
2024년 5월 4일
Walter Roberson
2024년 5월 5일
편집: Walter Roberson
2024년 5월 5일
data{j} = cell2struct(spdfcdfread(list), vars, 2);
Sonali
2024년 5월 5일
Walter Roberson
2024년 5월 6일
temp = cellfun(@(C) {C}, spdfcdfread(list));
data{j} = table(temp{:}, 'VariableNames', vars);
카테고리
도움말 센터 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!