how do I fprintf a power?

16 次查看(过去 30 天)
cwp
cwp 2024-10-22
编辑: Aquatris 2024-10-23,9:48
Hi, I can't figure out how to get fprintf() to display "r^2" without the "^". I have
fprintf("R^2; %.4f%s%.4f\n", gof.rsquare)
but this displays the "^". How do I fix this?

采纳的回答

Star Strider
Star Strider 2024-10-22
Using ‘char(178)’ is an option —
gof.rsquare = 0.975;
fprintf("R"+char(0178)+"; %.4f%s%.4f\n", gof.rsquare)
R²; 0.9750
.
  1 个评论
Aquatris
Aquatris 2024-10-23,9:42
编辑:Aquatris 2024-10-23,9:48
alternatively using unicodes (U+00B2 is superscript 2, ..B9 is superscript 1 etc);
gof.rsquare = 0.975;
fprintf("R\xB2; %.4f%s%.4f\n", gof.rsquare)
R²; 0.9750
fprintf("R\xB9; %.4f%s%.4f\n", gof.rsquare)
R¹; 0.9750

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by