Write a cell array in text file using Matlab

时光毁灭记忆、已成空白 提交于 2019-12-12 06:05:26

问题


I have a cell array with the size of 1*15.

whos C
Name      Size             Bytes  Class    Attributes
C         1x15            222520  cell   

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.

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!


回答1:


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


来源:https://stackoverflow.com/questions/27708871/write-a-cell-array-in-text-file-using-matlab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!