How do I print a '%' character using SPRINTF in MATLAB 7.7 (R2008b)?
조회 수: 118 (최근 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!