Doubt in fprintf with double bar

How can I print something like this: fprintf(fileID,'>|/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|< \r\n'); or like fprintf(fileID,'\\');
I get: Control Character '\/' is not valid. Thanks

 採用された回答

Walter Roberson
Walter Roberson 2015 年 10 月 19 日

1 投票

str = '>|/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|<';
fprintf(fileID, '%s\r\n', str);
fprintf(fileID, '\\\\')

その他の回答 (1 件)

Thorsten
Thorsten 2015 年 10 月 19 日
編集済み: Thorsten 2015 年 10 月 19 日

2 投票

\ starts many escape characters, like \n or \r. To print a single \, you have to use the escape character \\.
fprintf(fileID, '>|/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/|< \r\n');
fprintf(fileID, '\\\\')
Note that you can print to fileID 1, which is the standard display. This is quite useful for testing.
fprintf(1, '%%\\')

カテゴリ

ヘルプ センター および File ExchangeStructures についてさらに検索

製品

タグ

質問済み:

2015 年 10 月 19 日

編集済み:

2015 年 10 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by