# How to display pi symbol in the output?

62 visualizzazioni (ultimi 30 giorni)
GULZAR il 24 Ago 2023
Commentato: Hiro Yoshino il 24 Ago 2023
how to display pi symbol instead of numerical value in the out of the given code
clc; clear all; close all;
nA=3.3;nB=2.25;
% nB=3.3;nA=2.25;
S=sign(1-(nA^2/nB^2));
x=-1i*log(S);
if x>0
disp('Zak Phase of 0th band = ')
disp(pi)
else
disp('Zak Phase of 0th band = ')
disp('0')
end
Zak Phase of 0th band =
3.1416
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Fangjun Jiang il 24 Ago 2023
sprintf('\x3c0')
ans = 'π'
double('π')
ans = 960

Accedi per commentare.

### Risposta accettata

Dyuman Joshi il 24 Ago 2023
You can either use the symbolic math toolbox or print the symbol via the unicode value -
nA=3.3;nB=2.25;
% nB=3.3;nA=2.25;
S=sign(1-(nA^2/nB^2));
x=-1i*log(S);
if x>0
disp('Zak Phase of 0th band = ')
%pi as a symbolic number
disp(sym(pi))
%print the symbol via unicode value
fprintf('%c', 960)
else
disp('Zak Phase of 0th band = ')
disp('0')
end
Zak Phase of 0th band =
π
π
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Più risposte (2)

Nathan Hardenberg il 24 Ago 2023
Modificato: Nathan Hardenberg il 24 Ago 2023
You can display pi as a sybolic
disp(sym(pi))
π
Or you can use a π-character (𝜋 or π).
disp("𝜋")
𝜋
disp("π")
π
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Hiro Yoshino il 24 Ago 2023
S = sprintf('Zak Phase of 0th band = %c',960);
disp(S);
Zak Phase of 0th band = π
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Hiro Yoshino il 24 Ago 2023
Please refer to the list of Unicode for your help:List of Unicode characters

Accedi per commentare.

### Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by