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

조회 수: 118 (최근 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
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 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