Writing X Y values from char to a txt file
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (2 件)
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 件のコメント
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
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
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)
参考
カテゴリ
Help Center および File Exchange で Construct and Work with Object Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!