如何在Matlab GUI中显示希腊符号

时间:2013-12-17 16:55:56

标签: matlab user-interface

在Matlab中编写GUI时如何使用度数符号?我可以在绘图时使用^\circ,但在编写GUI时这不起作用。

到目前为止,这是我的GUI:

directory = 'Data';
SiteName = 'AAA';
done = false;
spcFrac = 2; %number of spaces = char;
num2delim = 20;
defSlt = 'aTemp';
loader = 'on';

fclose all;
outputOptions = {'Air temperature','aTemp'};
defaults = {'',''};
% long names for outputs
names    = {'latitude (deg N)','altitude (m)'};
lines = [4,5];
[~,b] = sortrows(outputOptions); vL = length(b);
outN = cell(vL,1);outA = outN;outUn = outN;
for k = 1:length(b)
    outUn{k}= outputOptions{b(k),1};
    outN{k} = outputOptions{b(k),1};
    outA{k} = outputOptions{b(k),2};
end

indx = strcmp(defSlt,outA);
slt{1} = outN{indx};
txt = outA{indx};
outN(indx) = [];

close all
bckColor = [.85 .85 .85];
figDims = [150 150 400 300];
lM = 15;
tM = 20;
rM = 15;
bM = 15;
pnS = 12;
bgPw = 180;
bgPh = 120;
btnH = 25;
txtH = 20;
txtW = 40;
txtS = 5;
spc = 9;
radioW = 150;
radioH = 20;

bigPanels(1,:) = [lM figDims(4)-bgPh-tM bgPw bgPh];
bigPanels(2,:) = bigPanels(1,:); bigPanels(2,1) = bigPanels(2,1)+pnS+bgPw;
filePanel = [bigPanels(2,1)+bgPw+pnS*2 bM+pnS+btnH ...
    figDims(3)-bgPw*2-lM-pnS*3-rM figDims(4)-tM-pnS-btnH-bM];
btns(1,:) = [lM bigPanels(1,2)-spc-btnH bgPw btnH];
btns(2,:) = [bigPanels(2,1) bigPanels(1,2)-spc-btnH bgPw btnH];
btns(3,:) = [filePanel(1)+filePanel(3)-bgPw bM bgPw btnH];
btns(4,:) = [filePanel(1) bM radioW radioH];

numTxtIn = numel(defaults);
rowsTxt = ceil(numTxtIn/2);
for p = 1:rowsTxt
    txtBoxL(p,:) = [lM bM+(p-1)*(pnS+txtH) txtW txtH];

    txtBoxR(p,:) = [lM+pnS+bgPw bM+(p-1)*(pnS+txtH) txtW txtH ];
    diaL(p,:) = [lM+txtW+txtS -txtS+bM+(p-1)*(pnS+txtH) txtBoxR(p,1)-...
        lM-txtW-pnS txtH ];
    diaR(p,:) = [txtBoxR(p,1)+txtW+txtS -txtS+bM+(p-1)*(pnS+txtH) ...
        txtBoxR(p,1)-lM-txtW-pnS txtH ];
end
S.fh = figure('units','pixels',...
              'position',figDims,...
              'menubar','none',...
              'resize','off',...
              'numbertitle','off',...
              'name','Configuration File','Color',bckColor);
          movegui(S.fh,'center')
outFrame=uipanel('Parent',S.fh,'BackgroundColor',bckColor,...
        'Title','Output options','FontSize',10);
        setpixelposition(outFrame,[lM-spc btns(1,2)-spc ...
        bgPw+spc*2 bgPh+btnH+spc*3+pnS]);

slcFrame=uipanel('Parent',S.fh,'BackgroundColor',bckColor,...
        'Title','Output selections','FontSize',10);
        setpixelposition(slcFrame,[bigPanels(2,1)-spc btns(1,2)-spc ...
        bgPw+spc*2 bgPh+btnH+spc*3+pnS]);
ParamFrame=uipanel('Parent',S.fh,'BackgroundColor',bckColor,...
        'Title','User parameters','FontSize',10);
        setpixelposition(ParamFrame,[btns(1,1)-spc ...
            bM-spc bgPw*2+pnS+spc*2 btns(1,2)-2*spc-2]);

for lm = 1:rowsTxt
    indr = rowsTxt-lm+1;
S.outT(1,indr) = uicontrol('style','edit',...
    'units','pix',...
    'position',txtBoxL(indr,:),...
    'HorizontalAlign','center',...
    'string','Remove',...
    'fontsize',8,'String',defaults{lm,1},...
    'callback',{@txt_call,lines(lm,1)},...
    'BackgroundColor','w');
S.outT(2,indr) = uicontrol('style','edit',...
    'units','pix',...
    'position',txtBoxR(indr,:),...
    'HorizontalAlign','center',...
    'string','Remove',...
    'fontsize',8,'String',defaults{lm,2},...
    'callback',{@txt_call,lines(lm,2)}...
    ,'BackgroundColor','w');
S.outD(1,indr) = uicontrol('style','text',...
    'units','pix',...
    'position',diaL(indr,:),...
    'HorizontalAlign','left',...
    'string','Remove',...
    'fontsize',8,'String',names{lm,1},'BackgroundColor',bckColor);
S.outD(2,indr) = uicontrol('style','text',...
    'units','pix',...
    'position',diaR(indr,:),...
    'HorizontalAlign','left',...
    'string','Remove',...
    'fontsize',8,'String',names{lm,2},'BackgroundColor',bckColor);
end

enter image description here

这里我想将degN更改为度数符号^ \ circ不起作用。

1 个答案:

答案 0 :(得分:3)

根据您要使用的符号,您可以使用扩展的ascii或unicode符号。因此,例如,^ \ circ为Alt+0176,它为您提供°(必须在键盘上键入数字,并且必须为零)。 µAlt+0181等。如果这不起作用,您还可以通过编程方式使用char()。因此char(176)将为您提供学位标志。

我应该补充一点,Alt+0XXX构造是一个MS Windows(它可以追溯到95 AFAIK)的快捷方式。我确信,MacOS有类似的键盘快捷键和你最喜欢的* nix风格。 char命令无处不在。

从上面的示例代码中,您只需要更改names的定义:

names    = {'latitude (°N)','altitude (m)'};

names    = {['latitude (' char(179) 'N)'],'altitude (m)'};