필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
me
me 2015년 11월 7일
댓글: Walter Roberson 2015년 11월 7일
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)
Walter Roberson
Walter Roberson 2015년 11월 7일
If GPS_Data is an array of character then
fprintf(fid2, '%s\n' ,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