Warning: Control Character '\Q' is not valid. fprintf

4 ビュー (過去 30 日間)
Asher Metzger
Asher Metzger 2016 年 3 月 3 日
編集済み: Stephen23 2016 年 3 月 6 日
Hi there,
I searched all over and this seems to be an undocumented problem. At least not heavily documented.
I am trying to modify a txt file by reading it into a cell array with fgetl and then make changes to the relevant lines and finally write a txt file with the changes using fprintf. I get the warning in the subject and these lines are not written. these lines are paths.
What am I doing wrong? or what would be the right way to escape the problem? the files are attached. no need to run further than line 31 in main.m. The functions after that are not needed for my question.
Thanks a bunch, Asher
  2 件のコメント
Stephen23
Stephen23 2016 年 3 月 3 日
編集済み: Stephen23 2016 年 3 月 6 日
This is quite well documented in the fprintf documentation. Image Analyst has shown you the correct way to use fprintf, using a format specifier string (exactly as per the fprintf documentation): instead of this:
fprintf(fid,A{1,i});
fprintf(fid,'\n');
(which will throw an error with '\Q' and many other character combinations) you simply need to read the fprintf documentation, and use a format string:
fprintf(fid, '%s\n', A{1,i});
Asher Metzger
Asher Metzger 2016 年 3 月 6 日
You're right it is documented. I just didn't understand it... Thanks a lot.

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

採用された回答

Image Analyst
Image Analyst 2016 年 3 月 3 日
You can print out a \Q if it's in a string. That's not the problem at all. The problem is that you don't have a format specifier string in your fprintf() statement. To fix, put '%s\n' in your fprintf().
fprintf(fid,'%s\n', A{1,i});
You don't need the second fprintf with just the backslash n because I combined it all into this single call to fprintf().
  1 件のコメント
Asher Metzger
Asher Metzger 2016 年 3 月 6 日
Thanks. Learning every day.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by