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

101 次查看(过去 30 天)
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
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 CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

尚未输入任何标签。

产品


版本

R2008b

Community Treasure Hunt

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

Start Hunting!

Translated by