How to write low level text to a file without interpretation

2 ビュー (過去 30 日間)
John Deer
John Deer 2019 年 11 月 27 日
編集済み: Rik 2019 年 11 月 27 日
Hello,
i want to filter a given textfile. Therefore i open a file and make a cell array with the desired lines of text.
Now i want to save the text into a textfile (*.txt).
The given lines are for example:
' -------- Iteration 0 --------'
' Masking 8% (1393) of the nominal rays'
' RMS = 21.6nm, PV = 163.9nm, d_t = 0s'
If i use fprintf, the output looks like this:
-------- Iteration 0 --------
Masking 8
RMS = 21.6nm, PV = 163.9nm, d_t = 0s
This is clearly because matlab interprets the '%'. I didn't check if other chars would be also interpretet by matlab.
I cannot modify the lines to write without investigating massive calculation-time (by checking every single line before writing).
Is there a way to write text low-level to a file without any interpretation?
Thanks

採用された回答

Rik
Rik 2019 年 11 月 27 日
編集済み: Rik 2019 年 11 月 27 日
If you want to write a char array, you should use the fprintf('%s', txt) syntax, otherwise fprintf will interpret your input as a format specification. (don't forget to add newline characters as needed, either in the char array itself or with '%s\n')
  2 件のコメント
John Deer
John Deer 2019 年 11 月 27 日
編集済み: Rik 2019 年 11 月 27 日
Thanks,
this works:
fprintf(fileID, '%s', InfoLine);
fprintf(fileID,'\r\n');
Rik
Rik 2019 年 11 月 27 日
You can also merge those two:
fprintf(fileID, '%s\r\n', InfoLine);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by