How do I print a '%' character using SPRINTF in MATLAB 7.7 (R2008b)?

103 ビュー (過去 30 日間)
MathWorks Support Team
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
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
Walter Roberson 2017 年 11 月 23 日
str2write = '% whatever 75% ';
str2write = regexprep( str2write, '%', '%%' );
or
str2write = '% whatever 75% ';
str2write = strrep( str2write, '%', '%%' );

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 11 月 23 日
sprintf('%s', '100%')
The % are only "eaten" if they occur in the first parameter, the format position.

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2008b

Community Treasure Hunt

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

Start Hunting!

Translated by