How to display pi symbol in the output?
조회 수: 96 (최근 30일)
이전 댓글 표시
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
채택된 답변
Dyuman Joshi
2023년 8월 24일
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
댓글 수: 0
추가 답변 (2개)
Nathan Hardenberg
2023년 8월 24일
편집: Nathan Hardenberg
2023년 8월 24일
You can display pi as a sybolic
disp(sym(pi))
Or you can use a π-character (𝜋 or π).
disp("𝜋")
disp("π")
댓글 수: 0
Hiro Yoshino
2023년 8월 24일
How about this?
S = sprintf('Zak Phase of 0th band = %c',960);
disp(S);
댓글 수: 1
Hiro Yoshino
2023년 8월 24일
Please refer to the list of Unicode for your help:List of Unicode characters
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!