Exaclty the title.
I know char(177) returns the plus/minus symbol but can't work out how to get it to display when matlab outputs to the command window.
fprintf('The measured volume of %fmm^{3} \x177 %fmm^{3} is equal to\nthe specified volume of %fmm^{3} \x177 %fmm^{3},\nand therefore the object passes quality inspection and can be released.\n',Vtot, DeltVrounded,VSpec,DeltaVSpec);

댓글 수: 1

Since the data you are printing is of character class, use the c conversion in the formatting operator for that data, e.g., '%c':
a = 10;
b = 1.5;
plus_minus_char = char(177);
fprintf('The measured whatever of %f %c %f is equal to the whatever ...',a,plus_minus_char,b)
The measured whatever of 10.000000 ± 1.500000 is equal to the whatever ...

댓글을 달려면 로그인하십시오.

 채택된 답변

Marcus Darnell
Marcus Darnell 2019년 9월 18일

4 개 추천

used \x00B1 and worked

추가 답변 (3개)

DNDNDN
DNDNDN 2025년 9월 27일
편집: DNDNDN 2025년 9월 27일

1 개 추천

fprintf("%c", 177)
Where 177 is the code for the plus/minus character. E.g.:
fprintf("100%c5", 177)
Outputs:
100±5
dpb
dpb 2019년 9월 18일

0 개 추천

pmchar=char(177);
fprintf(['The measured volume of %fmm^{3} ' pmchar '%fmm^{3} is equal to\nthe specified volume of %fmm^{3} ' pmchar '%fmm^{3},\nand therefore the object passes quality inspection and can be released.\n'], ...
Vtot, DeltVrounded,VSpec,DeltaVSpec);
I'd probably write the format string as a variable to be more readable, but that's just a style nit.
Josef Henthorn
Josef Henthorn 2020년 10월 28일

0 개 추천

The Latex code for this symbol is \pm

댓글 수: 1

Walter Roberson
Walter Roberson 2025년 9월 27일
However, latex formatting is not used for fprintf()

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Language Fundamentals에 대해 자세히 알아보기

태그

질문:

2019년 9월 18일

댓글:

2025년 9월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by