matlab——简单运算器

[复制链接]
632|0
 楼主| cooldog123pp 发表于 2024-6-22 20:40 | 显示全部楼层 |阅读模式
  1. h1=uicontrol(gcf,'style','radio',...
  2.     'string','加',...
  3.     'value',1,...
  4.     'position',[20 150 40 20],...
  5.     'callback',[...
  6.         'k=1;,',...
  7.         'set(h1,''value'',1),',...
  8.         'set(h2,''value'',0),',...
  9.         'set(h3,''value'',0)']);
  10. h2=uicontrol(gcf,'style','radio',...
  11.     'string','减',...
  12.     'position',[20 110 40 20],...
  13.     'callback',[...
  14.         'k=2;,',...
  15.         'set(h2,''value'',1),',...
  16.         'set(h1,''value'',0),',...
  17.         'set(h3,''value'',0)']);
  18. h3=uicontrol(gcf,'style','radio',...
  19.     'string','乘',...
  20.     'position',[20 70 40 20],...
  21.     'callback',[...
  22.         'k=3;,',...
  23.         'set(h3,''value'',1),',...
  24.         'set(h2,''value'',0),',...
  25.         'set(h1,''value'',0)']);
  26. e1=uicontrol(gcf,'style','edit',...
  27.     'position',[80 150 100 20]);
  28. e2=uicontrol(gcf,'style','edit',...
  29.     'position',[80 110 100 20]);
  30. e3=uicontrol(gcf,'style','edit',...
  31.     'position',[80 70 100 20]);
  32. b1=uicontrol(gcf,'style','pushbutton',...
  33.     'string','运算',...
  34.     'position',[200 150 80 30],...
  35.     'callback',[...
  36.         'x=str2num(get(e1,''string''));,',...
  37.         'y=str2num(get(e2,''string''));,',...
  38.         'switch k,',...
  39.         'case 1,',...
  40.         'z=x+y;,',...
  41.         'case 2,',...
  42.         'z=x-y;,',...
  43.         'case 3,',...
  44.         'z=x*y;,',...
  45.         'end,',...
  46.         'set(e3,''string'',num2str(z))']);
  47. b2=uicontrol(gcf,'style','pushbutton',...
  48.     'string','退出',...
  49.     'position',[200 100 80 30],...
  50.     'callback','close');


您需要登录后才可以回帖 登录 | 注册

本版积分规则

2304

主题

7628

帖子

31

粉丝
快速回复 在线客服 返回列表 返回顶部