필터 지우기
필터 지우기

combine numbers and symbols in print to txt file

조회 수: 1 (최근 30일)
Peter Larsen
Peter Larsen 2019년 2월 22일
댓글: Peter Larsen 2019년 2월 27일
Hi
I want to print a matrix
My input are:
LatLon=[ 57 42.682 10 36.159;
57 42.841 10 36.049......]
I want to print the output to a txt file to look like this.
Latdeg Latmin Londeg Lonmin
57 (Degrees sign) 42.682'N 10 (degrees sign) 36.159'E
57(degrees sign) 42.841'N 10 (degrees sign) 36.049'E
The degrees sign should be ^o .

답변 (1개)

Krishna Zanwar
Krishna Zanwar 2019년 2월 25일
Hi Peter,
Use the File Id of your text file instead of <fileId>
a = "%d ";
b=char(176);
c=" %f'N %d";
d=" %f'E \n";
formatSpec=strcat(a,b,c,b,d)
fprintf(<fileId>,formatSpec,LatLon(:,1),LatLon(:,2),LatLon(:,3),LatLon(:,4))
  댓글 수: 1
Peter Larsen
Peter Larsen 2019년 2월 27일
If I insert your code in my print, the txt file looks strange. My code is:
fileID=fopen('UTM2DM.txt','w');
fprintf(fileID,'%3d %4.3f 3d %6.3f\n','Latdeg','Latmin','Londeg','Lonmin');
a = "%d ";
b=char(176 );
c=" %f'N %d ";
d=" %f'E \n ";
formatSpec=strcat(a,b,c,b,d );
fprintf(fileID,formatSpec,LatLon(:,1),LatLon(:,2),LatLon(:,3),LatLon(:,4));
fclose(fileID);
Do you have an idea why my output in the txt file is so different?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by