write cell data into text file

When the elements in a cell matrix is numeric, like:

a = cell(10,1)
for i = 1:10
  a{i} = i;
end

% then, the following script should be like this:

fileID = fopen('celldata.txt','wt')
for row = 1:10
  fprintf(fileID,'%s\n' ,num2str(a{row,:}));
end
fclose(fileID);

 

There are two tricky points in this script.

1. fopen('celldata.txt','wt')  is really important. When it is changed to fopen('celldata.txt','w'), '\n' doesn't work on windows. As Jan Simon concluded, '\n' depends on the platform.

2. num2str is necessary, otherwise, it will be some weird squares in your file.

posted @ 2015-05-27 15:54  此间漫步  阅读(225)  评论(0编辑  收藏  举报