plus/minus inside fprinf statement
106 ビュー (過去 30 日間)
古いコメントを表示
Marcus Darnell
2019 年 9 月 18 日
コメント済み: Walter Roberson
2025 年 9 月 27 日 18:30
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 件のコメント
Voss
2025 年 9 月 27 日 12:31
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)
採用された回答
その他の回答 (3 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!