display special symbol in message box

조회 수: 4 (최근 30일)
son
son 2014년 8월 20일
댓글: Star Strider 2014년 8월 20일
hi, i use sprintf code but now it can't display the special symbol 'alpha'
clear all
close all
%%Insert value in Matlab
dlg_title = 'Insert Factor Value';
x1 = inputdlg('Enter number of channels:',dlg_title, [1 50]);
n = str2num(x1{:});
x2 = inputdlg('Enter input power for each channel (mW):',dlg_title, [1 50]);
p = str2num(x2{:})*10^-3;
x3 = inputdlg('Enter channel spacing (nm):',dlg_title, [1 50]);
delta_lambda = str2num(x3{:})*10^-9;
CreateStruct.Interpreter = 'tex';
CreateStruct.WindowStyle = 'modal';
choice = menu('Choose optical fiber type','Single-mode fiber ( G.652 )','Dispersion-shifted fiber ( G.653 )','Non-zero dispersion-shifted fiber ( G.655 )');
if choice==1
alphadb = 0.20;
dispersion=16;
slope=0.080;
A=80;
elseif choice==2
alphadb = 0.22;
dispersion=0;
slope=0.075;
A=50;
else
alphadb = 0.23;
dispersion=3;
slope=0.050;
A=72;
end
h = msgbox({sprintf('Fibre attenuation: \alpha = %g (dB/km)',alphadb)
'Derivative dispersion coefficient: s = dD/d\lambda = 0.075 (ps/nm^2.km)' },'Standard Values',CreateStruct);

채택된 답변

Star Strider
Star Strider 2014년 8월 20일
In sprintf, single ‘\’ are control characters for it and will throw an error if sprintf doesn’t recognise a valid control sequence, so to get it to print a ‘\’ that the TeX interpreter will see and interpret requires a double ‘\\’.
This worked for me, displaying both alpha and lambda as special characters:
h = msgbox({sprintf('Fibre attenuation: \\alpha = %g (dB/km)',alphadb)
'Derivative dispersion coefficient: s = dD/d\lambda = 0.075 (ps/nm^2.km)' },'Standard Values',CreateStruct);
  댓글 수: 2
son
son 2014년 8월 20일
thanks you help me so much
Star Strider
Star Strider 2014년 8월 20일
My pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by