Writing X Y values from char to a txt file

4 Ansichten (letzte 30 Tage)
as hz
as hz am 15 Okt. 2013
Bearbeitet: Image Analyst am 29 Okt. 2013
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

Antworten (2)

Cedric
Cedric am 15 Okt. 2013
Bearbeitet: Cedric am 15 Okt. 2013
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 Kommentare
as hz
as hz am 15 Okt. 2013
thx
Image Analyst
Image Analyst am 29 Okt. 2013
Bearbeitet: Image Analyst am 29 Okt. 2013
Please officially accept the best answer. You can only accept one answer, not more than one.

Melden Sie sich an, um zu kommentieren.


Azzi Abdelmalek
Azzi Abdelmalek am 15 Okt. 2013
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 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 15 Okt. 2013
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 am 15 Okt. 2013
thx

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by