How can we do for following fprintf formating

How can i show power 2 of x in fprintf as general format?

3 Kommentare

Ameer Hamza
Ameer Hamza am 27 Nov. 2020
Can you further explain? What is the output you expect in the command window or the file?
PULAK Kumer
PULAK Kumer am 27 Nov. 2020
How can we show this in fprintf
PULAK Kumer
PULAK Kumer am 27 Nov. 2020
Please tell sir..I want to see 2 as a superscript of x using fprintf

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Star Strider
Star Strider am 27 Nov. 2020

0 Stimmen

Try this:
fprintf('\tx%c\n', char(178))
producinig:
x²
.

2 Kommentare

PULAK Kumer
PULAK Kumer am 27 Nov. 2020
Thank you sir
Star Strider
Star Strider am 27 Nov. 2020
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Francis Adesayo
Francis Adesayo am 21 Nov. 2022

1 Stimme

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 Kommentare

Star Strider
Star Strider am 21 Nov. 2022
This is essentially doing the same thing as in my Answer, just not using fprintf.
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))
x¹ x² x³
Vectorised!
.
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by