MATLAB: Saving Cell array and String to text file.

cell arraystringtext file

I have a cell_in (combination of numeric, date&time & text data) of size mxn and need to save data in a text file.
Here is the code I have written and it works fine
fid = fopen(FilePath,'w');
for rows = 1:size(Cell_in,1)
fprintf(fid,'%s\n',Cell_in{rows,:});
end
fclose(fid)
Instead of doing it in a loop I changed it to string and saved data to text file using the following code
fid = fopen(FilePath,'w');
fprintf(fid,'%s\n',char(Cell_in));
fclose(fid)
and the text file is completely messed up. Am I doing something wrong?
1.If so what did I do wrong?
2. When loading a txt file to MATLAB one can extract the data as cell using
fid = fopen(FileName,'r');
txt_data = textscan(fid,'%s','delimiter','\n');
fclose(fid);
but why not the other way round is possible?

Best Answer

fid = fopen(FilePath,'w');
CT = Cell_in.';
fprintf(fid,'%s\n', CT{:});
fclose(fid)