Superscripts and subscripts in fprintf

조회 수: 88 (최근 30일)
Left Terry
Left Terry 2024년 12월 30일
편집: Stephen23 2024년 12월 31일
Is it possible to display text with subscripts using fprintf in R2016a ? I would like to change Nmax.
fprintf('\nMaximum value of N is Nmax = 2\n');
Maximum value of N is Nmax = 2

답변 (3개)

Abhas
Abhas 2024년 12월 30일
In MATLAB R2016a, "fprintf" does not support displaying text with subscripts directly because it outputs plain text, and subscripts are a feature of formatted text (like LaTeX or rich text). However, there are workarounds to display subscripts depending on the output medium:
  • If you need to display subscripts in a figure, you can use text or annotation with TeX or LaTeX formatting, which supports subscripts:
figure;
text(0.1, 0.5, 'Maximum value of N is N_{max} = 2', 'Interpreter', 'tex');
fprintf('y\x2098')
yₘ
I hope this helps!
  댓글 수: 4
Left Terry
Left Terry 2024년 12월 30일
I meant that even this does not work:
fprintf('y\x2098')
yₘ
Matt J
Matt J 2024년 12월 30일
편집: Matt J 2024년 12월 30일
It doesn't work.
It does in LiveScript or other rich text environments:
myfprintf('Maximum value of N is N_{max} = 2')
myfprintf('Minimum value of N is N_{min} = 1')
function myfprintf(str)
hF=figure;hAx=gca;
imagesc(nan(10,500),'AlphaData',0); axis image; axis off;
Ht=text(250,5,str,'Interpreter','tex','Horiz','right');
hF.InnerPosition(end)=hAx.OuterPosition(end)*30;
end

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


Image Analyst
Image Analyst 2024년 12월 30일

Adam Danz
Adam Danz 2024년 12월 30일
Not all letters have unicode subscripts but m, a, and x do, so you're in luck.
x = 2;
fprintf(1,'Maximum value of N is N%c%c%c=%.0f\n',[8344 8336 8339 x]);
Maximum value of N is Nₘₐₓ=2
More info
  • webnots page that lists unicodes for super- and subscript letters
  • subscript generator - to get the numeric unicode values, copy the results in matlab and run double('<results>')
  댓글 수: 5
Walter Roberson
Walter Roberson 2024년 12월 31일

Ah, that would be a matter of setting the command window font to one that supports unicode.

Left Terry
Left Terry 2024년 12월 31일
@Image Analyst When i use it i see boxes istead of subscripts like in the image posted above.

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

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by