plus/minus inside fprinf statement

조회 수: 171 (최근 30일)
Marcus Darnell
Marcus Darnell 2019년 9월 18일
답변: Josef Henthorn 2020년 10월 28일
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);

채택된 답변

Marcus Darnell
Marcus Darnell 2019년 9월 18일
used \x00B1 and worked

추가 답변 (2개)

dpb
dpb 2019년 9월 18일
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일
The Latex code for this symbol is \pm

태그

Community Treasure Hunt

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

Start Hunting!

Translated by