How can we do for following fprintf formating
이전 댓글 표시
How can i show power 2 of x in fprintf as general format?
댓글 수: 3
Ameer Hamza
2020년 11월 27일
Can you further explain? What is the output you expect in the command window or the file?
PULAK Kumer
2020년 11월 27일
PULAK Kumer
2020년 11월 27일
채택된 답변
추가 답변 (2개)
Francis Adesayo
2022년 11월 21일
1 개 추천
you can type x and then on your keyboard press and hold the alt key while you type 253 on the number pad on the right of the keyboard. This only works if your keyboard has the number pad.
You will get x².
Likewise, math symbols such as the integral symbol --> ∫ x² dx can be gotten by pressing the windows button and semicolon button. And then go to symbols tab, and then to math symbols and select the one you want. This way you dont have to type any special ascii code or use %c.
댓글 수: 4
Star Strider
2022년 11월 21일
Note that doing this with fprintf is the actual question being posed here.
%use alt+253 to get superscript 2.
fprintf('x²\n')
In my mind, this makes the code look cleaner than say:
fprintf('x%c',char(178))
Proof of concept —
ssc = [185 178 179];
fprintf('\tx%c\n', char(ssc))
Vectorised!
.
Francis Adesayo
2022년 11월 21일
The OP just wanted x² printed on the command window. I simply provided an alternative way which has the added benefit of making the code look cleaner. Cheers Star Strider.
Ameer Hamza
2020년 11월 27일
0 개 추천
It is not possible to do such thing in command window currently: https://www.mathworks.com/matlabcentral/answers/255568-putting-a-subscript-into-a-string-displaying-the-command-window
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!