How do I print a '%' character using SPRINTF in MATLAB 7.7 (R2008b)?
103 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2009 年 6 月 27 日
回答済み: Walter Roberson
2017 年 11 月 23 日
I would like to print a string containing the '%' character. However, when I attempt the following:
sprintf('100%')
The output reads:
100
採用された回答
MathWorks Support Team
2009 年 6 月 27 日
To escape the percent symbol, use two percent signs. For example:
sprintf('100%%')
Yields the output:
100%
1 件のコメント
Walter Roberson
2017 年 11 月 23 日
str2write = '% whatever 75% ';
str2write = regexprep( str2write, '%', '%%' );
or
str2write = '% whatever 75% ';
str2write = strrep( str2write, '%', '%%' );
その他の回答 (1 件)
Walter Roberson
2017 年 11 月 23 日
sprintf('%s', '100%')
The % are only "eaten" if they occur in the first parameter, the format position.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!