Formatting Subscript, and Superscript in Text

조회 수: 1,038 (최근 30일)
Kartikeya Singh-Freeman
Kartikeya Singh-Freeman 2021년 10월 10일
댓글: Stephen23 2024년 11월 11일 9:14
Need some help adding subscripts, and superscripts to text descriptions.
title("D_{0} D^{0}")
title(sprintf('D_{0} D^{0}'))
title(sprintf('D_{0} D^{0}')) applies the subscript, and superscript 0 to the title, however if I use sprintf without the title function the subscript, and superscript is not applied.
sprintf('D_{0} D^{0}')
ans = 'D_{0} D^{0}'

답변 (1개)

Star Strider
Star Strider 2021년 10월 10일
Note that the sprintf call is not required for this, unless it is necessary to also print variables —
text(0.4, 0.4, sprintf('D_{0} D^{0}'))
text(0.6, 0.6, sprintf('$D_{0} D^{0}$'), 'Interpreter','latex')
text(0.5, 0.5, 'D_{0} D^{0}')
text(0.7, 0.7, '$D_{0} D^{0}$', 'Interpreter','latex')
Experiment to get different results.
.
  댓글 수: 4
Captain Karnage
Captain Karnage 2022년 9월 22일
The answer is a useful tip, but the OP's question was not answered. I have the same question. Is there a way for MATLAB to show a superscript or subscript outside of labels on a figure? Like, in the command/output window?
Star Strider
Star Strider 2022년 9월 22일
@Captain Karnage — The Live Editor () might be an option (I rarely use it) however the Command Window is restricted to the ASCII character set. So something like -40°C or e=mc² would appear as it does here, however what isn’t provided in a particular ASCII font wouldn’t be available.

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by