필터 지우기
필터 지우기

Writing X Y values from char to a txt file

조회 수: 3 (최근 30일)
as hz
as hz 2013년 10월 15일
편집: Image Analyst 2013년 10월 29일
Hi,
I have a string with the following structure X1 Y1;X2 Y2; . . . ;Xn Yn (class char).
How can I save this information in a txt file with this structure?
X1 Y1
X2 Y2
. . .
Xn Yn
Thanks

답변 (2개)

Cedric
Cedric 2013년 10월 15일
편집: Cedric 2013년 10월 15일
If your char class variable is named str:
fid = fopen( 'myFile.txt', 'w' ) ;
fprintf( fid, strrep( str, ';', '\n' )) ; % Or '\r\n' if you want
fclose( fid ) ; % to be Windows-friendly.
  댓글 수: 4
as hz
as hz 2013년 10월 15일
thx
Image Analyst
Image Analyst 2013년 10월 29일
편집: Image Analyst 2013년 10월 29일
Please officially accept the best answer. You can only accept one answer, not more than one.

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


Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 15일
n=5
str=regexp(sprintf('X%d Y%d ',repmat(1:n,2)),'X\d\s+Y\d','match')
fid=fopen('file.txt','w')
fprintf(fid,'%s\r\n',str{:})
fclose(fid)
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 15일
C = '12 14; 13 56; 89 45; 892 45; 89 425; 189 425; 892 15'
str=regexp(C,';','split')
fid=fopen('file.txt','w')
fprintf(fid,'%s\r\n',str{:})
fclose(fid)
as hz
as hz 2013년 10월 15일
thx

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

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by