How can i write this to a file?
1 回表示 (過去 30 日間)
古いコメントを表示
I have a variable y which i want to write to a text file in the following way:
RouteOrder('1','1','1','1'):=y(1,1,1,1);
RouteOrder('1','1','1','2'):=y(1,1,1,2);
etc
I dont know how to use the ' as output in the file, therefore i replaced them with a's so i can later replace all the a's with '
I currently have
fid=fopen('y.txt')
fs='OrderRoute(a%da,a%da,a%da,a%da):=%d'
i loop j loop k loop l loop
a=[i,j,k,l,y(i,j,k,l)]
fprintf(fid,fs,a,'\n')
Which results in a file that has only one line just like using (fid,fs,'/n'a
Using fprintf(fid,'\n',fs,a) instead results in an empty file with the right amount of lines.
0 件のコメント
採用された回答
dpb
2013 年 8 月 12 日
You have to double-up the tic marks to include them. It's in the details of the doc for the various xprintf() functions...
fmt=['RouteOrder(' repmat('''%d'',',1,4) '):=%f\n']
fmt =
RouteOrder('%d','%d','%d','%d',):=%f\n
>> sprintf(fmt,1,1,1,1,.5)
ans =
RouteOrder('1','1','1','1',):=0.500000
>>
Salt the formatting to suit; you may want to add a field width for the subscripts if you want the output aligned neatly w/ increasing subscript values and the precision of the output value of course.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!