Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
me
me am 7 Nov. 2015
Kommentiert: Walter Roberson am 7 Nov. 2015
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

Antworten (1)

dpb
dpb am 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 Kommentare
me
me am 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)
Walter Roberson
Walter Roberson am 7 Nov. 2015
If GPS_Data is an array of character then
fprintf(fid2, '%s\n' ,GPS_Data.')

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by