matlab gui编写计算器,科学网—纯 MATLAB 代码 编写gui ……计算器 - 程黎鹿的博文...

纯 MATLAB 代码 编写gui ……计算器

已有 5333 次阅读

2009-1-20 22:28

||系统分类:科研笔记|

MATLAB, gui, 计算器

%一个简单的计算器

h0=figure('toolbar','none',...

'position',[200 60 220 240],...

'name','简单计算器');

b0=uicontrol('parent',h0,...

'units','points',...

'tag','b0',...

'style','pushbutton',...

'string','0',...

'fontsize',12,...

'position',[5 15 35 20],...

'backgroundcolor',[0.75 0.75 0.75],...

'callback',[...

'if k==''0''&i==0,',...

'errordlg(''首位不能为0''),',...

'else,',...

'k=[k,''0''];,',...

'if k==''00'',',...

'k=''0'';,',...

'end,',...

'set(e1,''string'',k);,',...

'end']);

b15=uicontrol('parent',h0,...

'units','points',...

'tag','b15',...

'style','pushbutton',...

'string','=',...

'fontsize',12,...

'position',[45 15 35 20],...

'backgroundcolor',[0.75 0.75 0.75],...

'callback',[...

'k=get(e1,''string'');,',...

'if g==''+'',',...

'm=m+str2num(k);,',...

'end,',...

'if g==''-'',',...

'm=m-str2num(k);,',...

'end,',...

'if g==''*'',',...

'm=m*str2num(k);,',...

'end,',...

'if g==''/'',',...

'if k==''0'',',...

'errordlg(''除数不能为0'');,',...

'end,',...

'm=m/str2num(k);,',...

'end,',...

'set(e1,''string'',num2str(m));,',...

'i=0;']);

b11=uicontrol('parent',h0,...

'units','points',...

'tag','b11',...

'style','pushbutton',...

'string','+',...

'fontsize',12,...

'position',[85 15 35 20],...

'backgroundcolor',[0.75 0.75 0.75],...

'callback',[...

'i=i+1;,',...

'if i==1,',...

'm=str2num(k);,',...

'set(e1,''string'',''0'');,',...

'end,',...

'if i>1,',...

'k=get(e1,''string'');,',...

'if g==''+'',',...

'm=m+str2num(k);,',...

'end,',...

'if g==''-'',',...

'm=m-str2num(k);,',...

'end,',...

'if g==''*'',',...

'm=m*str2num(k);,',...

'end,',...

'if g==''/'',',...

'if k==''0'',',...

'errordlg(''除数不能为0'');,',...

'end,',...

'm=m/str2num(k);,',...

'end,',...

'set(e1,''string'',num2str(m));,',...

'i=1;,',...

'end,',...

'k=''0'';,',...

'g=''+'';']);

b16=uicontrol('parent',h0,...

'units','points',...

'tag','b16',...

'style','pushbutton',...

'string','关闭',...

'fontsize',12,...

'position',[125 15 35 20],...

'backgroundcolor',[0.75 0.75 0.75],...

'callback','close');

b1=uicontrol('parent',h0,...

'units','points',...

'tag','b1',...

'style','pushbutton',...

'string','1',...

'fontsize',12,...

'position',[5 45 35 20],...

'backgroundcolor',[0.75 0.75 0.75],...

'callback',[...

'if k==''0'',',...

'k='''';,',...

'end,',...

'k=[k,''1''];,',...

'set(e1,''string'',k);']);

b2=uicontrol('parent',h0,...

'units','points',...

'tag','b2',...

'style','pushbutton',...

'string','2',...

'fontsize',12,...

'position',[45 45 35 20],...

'backgroundcolor',[0.75 0.75 0.75],...

'callback',[...

'if k==''0'',',...

'k='''';,',...

'end,',...

'k=[k,''2''];,',...

'set(e1,''string'',k);']);

b3=uicontrol('parent',h0,...

'units','points',...

'tag','b3',...

'style','pushbutton',...

'string','3',...

'fontsize',12,...

'position',[85 45 35 20],...

'backgroundcolor',[0.75 0.75 0.75],...

'callback',[...

'if k==''0'',',...

'k='''';,',...

'end,',...

'k=[k,''3''];,',...

'set(e1,''string'',k);']);

b14=uicontrol('parent',h0,...

'units','points',...

'tag','b14',...

'style','pushbutton',...

'string','/',...

'fontsize',12,...

'position',[125 45 35 20],...

'backgroundcolor',[0.75 0.75 0.75],...

'callback',[...

'i=i+1;,',...

'if i==1,',...

'm=str2num(k);,',...

'set(e1,''string'',''0'');,',...

'end,',...

'if i>1,',...

'k=get(e1,''string'');,',...

'if k==''0'',',...

'errordlg(''除数不能为0'');,',...

'end,',...

'if ~(k==''0''),',...

'if g==''+'',',...

'm=m+str2num(k);,',...

'end,',...

'if g==''-'',',...

'm=m-str2num(k);,',...

'end,',...

'if g==''*'',',...

'm=m*str2num(k);,',...

'end,',...

'if g==''/'',',...

'm=m/str2num(k);,',...

'end,',...

'set(e1,''string'',num2str(m));,',...

'end,',...

'i=1;,',...

'end,',...

'k=''0'';,',...

'g=''/'';']);

b4=uicontrol('parent',h0,...

'units','points',...

'tag','b4',...

'style','pushbutton',...

'string','4',...

'fontsize',12,...

'position',[5 75 35 20],...

'backgroundcolor',[0.75 0.75 0.75],...

'callback',[...

'if k==''0'',',...

'k='''';,',...

'end,',...

'k=[k,''4''];,',...

'set(e1,''string'',k);']);

b5=uicontrol('parent',h0,...

'units','points',...

'tag','b5',...

'style','pushbutton',...

'string','5',...

'fontsize',12,...

'position',[45 75 35 20],...

'backgroundcolor',[0.75 0.75 0.75],...

'callback',[...

'if k==''0'',',...

'k='''';,',...

'end,',...

'k=[k,''5''];,',...

'set(e1,''string'',k);']);

b6=uicontrol('parent',h0,...

'units','points',...

'tag','b6',...

'style','pushbutton',...

'string','6',...

'fontsize',12,...

'position',[85 75 35 20],...

'backgroundcolor',[0.75 0.75 0.75],...

'callback',[...

'if k==''0'',',...

'k='''';,',...

'end,',...

'k=[k,''6''];,',...

'set(e1,''string'',k);']);

b13=uicontrol('parent',h0,...

'units','points',...

'tag','b13',...

'style','pushbutton',...

'string','*',...

'fontsize',12,...

'position',[125 75 35 20],...

'backgroundcolor',[0.75 0.75 0.75],...

'callback',[...

'i=i+1;,',...

'if i==1,',...

'm=str2num(k);,',...

'set(e1,''string'',''0'');,',...

'end,',...

'if i>1,',...

'k=get(e1,''string'');,',...

'if g==''+'',',...

'm=m+str2num(k);,',...

'end,',...

'if g==''-'',',...

'm=m-str2num(k);,',...

'end,',...

'if g==''*'',',...

'm=m*str2num(k);,',...

'end,',...

'if g==''/'',',...

'if k==''0'',',...

'errordlg(''除数不能为0'');,',...

'end,',...

'm=m/str2num(k);,',...

'end,',...

'set(e1,''string'',num2str(m));,',...

'i=1;,',...

'end,',...

'k=''0'';,',...

'g=''*'';']);

b7=uicontrol('parent',h0,...

'units','points',...

'tag','b7',...

'style','pushbutton',...

'string','7',...

'fontsize',12,...

'position',[5 105 35 20],...

'backgroundcolor',[0.75 0.75 0.75],...

'callback',[...

'if k==''0'',',...

'k='''';,',...

'end,',...

'k=[k,''7''];,',...

'set(e1,''string'',k);']);

b8=uicontrol('parent',h0,...

'units','points',...

'tag','b8',...

'style','pushbutton',...

'string','8',...

'fontsize',12,...

'position',[45 105 35 20],...

'backgroundcolor',[0.75 0.75 0.75],...

'callback',[...

'if k==''0'',',...

'k='''';,',...

'end,',...

'k=[k,''8''];,',...

'set(e1,''string'',k);']);

b9=uicontrol('parent',h0,...

'units','points',...

'tag','b9',...

'style','pushbutton',...

'string','9',...

'fontsize',12,...

'position',[85 105 35 20],...

'backgroundcolor',[0.75 0.75 0.75],...

'callback',[...

'if k==''0'',',...

'k='''';,',...

'end,',...

'k=[k,''9''];,',...

'set(e1,''string'',k);']);

b12=uicontrol('parent',h0,...

'units','points',...

'tag','b12',...

'style','pushbutton',...

'string','-',...

'fontsize',12,...

'position',[125 105 35 20],...

'backgroundcolor',[0.75 0.75 0.75],...

'callback',[...

'i=i+1;,',...

'if i==1,',...

'm=str2num(k);,',...

'set(e1,''string'',''0'');,',...

'end,',...

'if i>1,',...

'k=get(e1,''string'');,',...

'if g==''+'',',...

'm=m+str2num(k);,',...

'end,',...

'if g==''-'',',...

'm=m-str2num(k);,',...

'end,',...

'if g==''*'',',...

'm=m*str2num(k);,',...

'end,',...

'if g==''/'',',...

'if k==''0'',',...

'errordlg(''除数不能为0'');,',...

'end,',...

'm=m/str2num(k);,',...

'end,',...

'set(e1,''string'',num2str(m));,',...

'i=1;,',...

'end,',...

'k=''0'';,',...

'g=''-'';']);

e1=uicontrol('parent',h0,...

'units','points',...

'tag','e1',...

'style','edit',...

'horizontalalignment','right',...

'fontsize',12,...

'string','0',...

'position',[45 135 115 20],...

'backgroundcolor',[1 1 1]);

k=get(e1,'string');

i=0;

m=0;

转载本文请联系原作者获取授权,同时请注明本文来自程黎鹿科学网博客。

链接地址:http://blog.sciencenet.cn/blog-95275-210939.html

上一篇:Matlab_dsolve

下一篇:MATLAB_转圈的球

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值