MATLAB - 将单元格数组写入csv文件 [英] MATLAB - write cell array to csv file
本文介绍了MATLAB - 将单元格数组写入csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个有字符和数字作为值的单元格数组。什么是最简单的方法,在一个csv文件中逐行输出它,保持单元格数组的结构?
例如,如果单元格数组为
I have a cell array that has both characters and numbers as values. What is the simplest way to output it in a csv file, row by row, maintaining the structure of the cell array? For example, if the cell array is
[abc] [1] [131]
[def] [] []
[gh] [13] [999]
该文件看起来像
I want the file to look like
abc,1,131
def,,
gh,13,999
推荐答案
示例:
%# cellarray
C = {
'abc' [1] [131]
'def' [] []
'gh' [13] [999]
};
%# write line-by-line
fid = fopen('file.csv','wt');
for i=1:size(C,1)
fprintf(fid, '%s,%d,%d\n', C{i,:});
end
fclose(fid);
这篇关于MATLAB - 将单元格数组写入csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文