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

2 views (last 30 days)
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

Answers (1)

dpb
dpb on 7 Nov 2015
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 Comments
me
me on 7 Nov 2015
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)

Sign in to comment.

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!