使用Matlab在文本文件中写入一个单元格数组 [英] Write a cell array in text file using Matlab
问题描述
我有一个大小为1 * 15的单元格数组.
I have a cell array with the size of 1*15.
whos C
Name Size Bytes Class Attributes
C 1x15 222520 cell
每个单元中有1170个元素. 15个单元格是字符串和数字的混合体.我想将所有这些元素保存到一个以逗号为分隔符的文本文件中.
In each cell, there are 1170 elements. The 15 cells are mixture of strings and numbers. I want to save all these elements to a text file with coma as delimiter.
我尝试使用函数 dlmcell 、dlmcell('file_out.txt.,C,'delimiter',','),则只能将每个单元格的第一个值写入文本文件.并且包含字符串的单元格无法写入文本文件.
I tried to use the function dlmcell, dlmcell('file_out.txt.,C,'delimiter',','), it can only write the first value of each cell to the text file. And the cell contains string cannot be write to the text file.
任何人都可以帮忙吗?谢谢!
Can anyone help? Thanks!
推荐答案
I just found in http://cn.mathworks.com/help/matlab/import_export/write-to-delimited-data-files.html write cell data using fprintf. May help!
[nrows,ncols] = size(C);
for row = 1:nrows
fprintf(fileID,formatSpec,C{row,:});
end
这篇关于使用Matlab在文本文件中写入一个单元格数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!