How do you print a cell matrix of different data types into a txt file

1 次查看(过去 30 天)
It has 11 columns and about 7000 rows. the first row is full of char type data. after the first row the 1st, 2nd, 5th-11th are all double types. The 3rd and 4th row are char types. How would I copy this matrix into a txt file. I tried the following but apparently fprintf doesn't work with cell inputs.
output_fileName = 'gebreegziabher.txt';
fid2 =fopen(output_fileName, 'w');
fprintf(fid2, '%s\n', 'GPS Data');
fprintf(fid2, '%s' ,GPS_Data); %GPS_Data is the name of the cell matrix

回答(1 个)

dpb
dpb 2015-11-7
A major hassle it is, indeed...to use fprintf you've got to write a specific formatting string for every line so in an irregular file such as this it's a real parsing nuisance.
I don't have a version which supports it but check out whether there's an output method for the new table data type that will handle mixed types more easily. Other than that, only better idea I've got is to do a conversion internally of all of the numeric files/rows to character via num2str or alternate and then can use a single '%s' format string for each row.
  2 个评论
me
me 2015-11-7
I tuned everything in the matrix into a string, but it still wont print it in to the txt file. is this not the correct format? fprintf(fid2, '%s' ,GPS_Data)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by