Bryan YU
Bryan YU

Reputation: 77

Outputing data to .txt file in matlab has error

The c:\answer2.txt file data looks like 3957.7913 11618.2937 72.56 3957.7913 11618.2937 72.56 ......(GPGGA format:latitude, longitude and height).

I want to convert the data to decimal: 39.963188 116.304895 72.56 ......

The code has an error in line 19:Error in ==> earth at 19
fprint(fp,'%f %f %f ',X2(i),Y2(i),Z2(i)); (tip:earth is matlab script name)

How can I modify the code to avoid this error?

The file that has been handled has latitude, longitude and height coordinates which are GPGGA(one type of NMEA) format. Matlab will show these coordinates in decimal instead of degree, minute.

 fid = fopen('c:\answer2.txt');
 [A, count] = fscanf(fid,'%f ',inf);
 fid1=['earth','.txt'];
 fp=fopen(fid1,'wt');
 B=reshape(A,3,count/3);
 X=B(1,:);%ddmm.mmmm latitude coordinate
 Y=B(2,:);%        longitude coordinate
 Z=B(3,:);%          height coordinate
 X2=(X-3900)/60+39;
 Y2=(Y-11600)/60+116;
 Z2=Z;
 for i=1:count/3
     fprint(fp,'%f %f %f ',X2(i),Y2(i),Z2(i));
 end
 fclose(fp);
 fclose(fid);

Upvotes: 0

Views: 58

Answers (1)

Bryan YU
Bryan YU

Reputation: 77

Change fprint to fprintf. If so, anything should be OK

Upvotes: 0

Related Questions