How do I print a '%' character using SPRINTF in MATLAB 7.7 (R2008b)?
126 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 27 Jun. 2009
Beantwortet: Walter Roberson
am 23 Nov. 2017
I would like to print a string containing the '%' character. However, when I attempt the following:
sprintf('100%')
The output reads:
100
Akzeptierte Antwort
MathWorks Support Team
am 27 Jun. 2009
To escape the percent symbol, use two percent signs. For example:
sprintf('100%%')
Yields the output:
100%
1 Kommentar
Walter Roberson
am 23 Nov. 2017
str2write = '% whatever 75% ';
str2write = regexprep( str2write, '%', '%%' );
or
str2write = '% whatever 75% ';
str2write = strrep( str2write, '%', '%%' );
Weitere Antworten (1)
Walter Roberson
am 23 Nov. 2017
sprintf('%s', '100%')
The % are only "eaten" if they occur in the first parameter, the format position.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!