代码语言:javascript复制
h0=figure('toolbar','none',...
'position',[200 150 350 200],...
'name','实例');
choose=1;
e1=uicontrol('parent',h0,...
'units','points',...
'tag','e1',...
'style','edit',...
'backgroundcolor',[1 1 1],...
'min',0,...
'max',2,...
'fontsize',12,...
'horizontalalignment','left',...
'position',[20 20 120 100]);
t1=uicontrol('parent',h0,...
'units','points',...
'tag','t1',...
'style','text',...
'string','请输入字母(大小写皆可):',...
'fontsize',10,...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 125 120 15]);
b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','开始统计',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[180 100 60 20],...
'callback',[...
's=get(e1,''string'');,',...
'n=length(s);,',...
'jb=0;,',...
'jl=0;,',...
'for i=1:n,',...
'if (abs(s(i))>64)&(abs(s(i))<91),',...
'jb=jb 1;,',...
'end,',...
'if (abs(s(i))>96)&(abs(s(i))<123),',...
'jl=jl 1;,',...
'end,',...
'end,',...
'j=jb jl;,',...
'if choose==1,',...
'msgbox([''共有字母'',num2str(j),''个!'',''其中大写字母'',num2str(jb),''个!''],''统计结果''),',...
'end,',...
'if choose==2,',...
'msgbox([''共有字母'',num2str(j),''个!'',''其中小写字母'',num2str(jl),''个!''],''统计结果'');,',...
'end']);
u1=uimenu('parent',h0,...
'label','字母分类',...
'backgroundcolor',[0.75 0.75 0.75],...
'tag','u1');
u11=uimenu('parent',u1,...
'label','大写字母',...
'backgroundcolor',[0.75 0.75 0.75],...
'tag','u11',...
'checked','on',...
'callback',[...
'set(u11,''checked'',''on'');,',...
'set(u12,''checked'',''off'');,',...
'choose=1;']);
u12=uimenu('parent',u1,...
'label','小写字母',...
'backgroundcolor',[0.75 0.75 0.75],...
'tag','u12',...
'callback',[...
'set(u12,''checked'',''on'');,',...
'set(u11,''checked'',''off'');,',...
'choose=2;']);
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'style','pushbutton',...
'string','清除',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[180 60 60 20],...
'callback','set(e1,''string'','''')');
b3=uicontrol('parent',h0,...
'units','points',...
'tag','b3',...
'style','pushbutton',...
'string','关闭',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[180 20 60 20],...
'callback','close');