从matlab导出嵌套单元格数组到excel

xam8gpfp  于 2023-03-19  发布在  Matlab
关注(0)|答案(1)|浏览(151)

我有一个嵌套单元格数组,其中每个单元格有三列,但行数不同。我需要将值导出到excel,同时保持列不变,但使用writecell时出现错误“不支持嵌套单元格数组”。如何将值导出到excel?
下面是一个简单的例子:

A1 = {1,1,1};
A2 = {2,2,2;2,2,2};
A3 = {3,3,3;3,3,3;3,3,3};
A = {A1, A2, A3}; 
writecell(A, 'mydata.xlsx');
au9on6nz

au9on6nz1#

A1 = {1,1,1};
A2 = {2,2,2;2,2,2};
A3 = {3,3,3;3,3,3;3,3,3};
A = {A1, A2, A3};
[~,NoCells]=size(A);
for aa=1:NoCells
writecell(A{aa}, 'mydata.xlsx','WriteMode','append');
end

**edit:**正如wolfie在注解中所建议的,代码可以缩短为:

A1 = {1,1,1};
A2 = {2,2,2;2,2,2};
A3 = {3,3,3;3,3,3;3,3,3};
A = {A1, A2, A3};
for aa=1:size(A,2)
writecell(A{aa}, 'mydata.xlsx','WriteMode','append');

相关问题