1 / 29

中華技術學院電子系

China Institute of Technology. 控制系統模擬 報告. 中華技術學院電子系. 題目 : 小算盤之製作 指導教授:蔡 樸 生 班 級:院 子 二 甲 學生姓名:洪 蘭 榮 學  號:9073001. The Department of Electronics Engineering. function calc(action,a0,stra) % %Date:2003/06/16 by lan-yo hong % if nargin <1, clear all;close; action='open';

tyra
Download Presentation

中華技術學院電子系

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. China Institute of Technology 控制系統模擬報告 中華技術學院電子系 題目:小算盤之製作 指導教授:蔡 樸 生 班 級:院 子 二 甲 學生姓名:洪 蘭 榮 學  號:9073001 The Department of Electronics Engineering

  2. function calc(action,a0,stra) % %Date:2003/06/16 by lan-yo hong % if nargin <1, clear all;close; action='open'; end if nargin==2 stra=a0; end if strcmp(action,'open') ScreenOnColor=[0.35 0.425 0.35]; ScreenOnColor1=[0.25 0.288 0.25]; fig1=figure(1); set(fig1,'Color',[0.422 0.421 0.421], ... 'Name','SCIENTIFIC CALCULATOR', ... 'menubar','none',... 'Position',[340 40 350 504]); %============================================================ % design data for display window %--------------------------------- left=0.02; bottom=0.732; top=0.9844; texthigh=0.0585; width=0.078; frm2h=0.022; insidw=0.01; insidh=0.006; border=[insidw insidh -2*insidw -2*insidh]; % First frame for undercolor frm1pst=[left bottom 1-2*left top-bottom]; frm2pst=frm1pst+[left 1.1*left -2*left -1.6*left-texthigh]; frm3pst=frm2pst+[width frm2h -2*width -2*frm2h]; uicontrol('Style','frame', ... 'Units','normalized', ... 'Position',frm1pst, ... 'BackgroundColor',[0 0 0]);

  3. % Second frame for undercolor • uicontrol('Style','frame', ... • 'Units','normalized', ... • 'Position',frm2pst, ... • 'BackgroundColor',[0.29 0.29 0.29]); • % Third frame for undercolor • text4=uicontrol(fig1,... • 'Style','frame', ... • 'Units','normalized', ... • 'Position',frm3pst, ... • 'BackgroundColor',ScreenOnColor1); • % ---- static text------------------------------------- • % first statice text for display window - line 3 • text0high=(frm3pst(4)-2*insidh)/3; • textpst=frm3pst+[insidw insidh -2*insidw -2*insidh]; • text1pst=textpst+[0 2*text0high 0 -2*text0high]; • text2pst=textpst+[0 text0high 0 -2*text0high]; • text3pst=textpst+[0 0 0 -2*text0high]; • sectntext=text3pst-[0 0 15*text3pst(3)/16 0]; • text7pst=sectntext;%Deg • text8pst=text7pst+[text3pst(3)/16 0 0 0];%Rad • text9pst=text8pst+[text3pst(3)/16 0 0 0];%Gra • text10pst=[text9pst(1)+text9pst(3)*1.7 0.782 0.095 0.0350];%hyp • text11pst=[text10pst(1)+text10pst(3) 0.782 0.095 0.0350];%inv • text12pst=[text11pst(1)+text11pst(3)*1.4 0.782 0.12 0.0350];%short • text13pst=[text12pst(1)+text12pst(3) 0.782 0.11 0.0350];%long • text14pst=[text13pst(1)+text13pst(3) 0.782 0.11 0.0350];%exp • adj=2.1; • text7pst=text7pst+border/adj; • text8pst=text8pst+border/adj; • text9pst=text9pst+border/adj; • text10pst=text10pst+border/adj; • text11pst=text11pst+border/adj; • text12pst=text12pst+border/adj; • text13pst=text13pst+border/adj; • text14pst=text14pst+border/adj; • text3=uicontrol(fig1,... • 'Style','text', ... • 'Units','normalized', ... • 'Position',text3pst, ... • 'BackgroundColor',ScreenOnColor,... • 'foregroundcolor',[0 0 0],... • 'string','');

  4. % second static text for display window - line 2 • text2=uicontrol(fig1,... • 'Style','text', ... • 'Units','normalized', ... • 'Position',text2pst, ... • 'FontWeight','bold', ... • 'horizontalalignment','right',... • 'FontSize',9, ... • 'BackgroundColor',ScreenOnColor,... • 'foregroundcolor',[0 0 0]); • % third static text for display window - line 1 • text1=uicontrol(fig1,... • 'Style','text', ... • 'Units','normalized', ... • 'Position',text1pst, ... • 'horizontalalignment','left',... • 'FontSize',9, ... • 'FontWeight','bold', ... • 'BackgroundColor',ScreenOnColor,... • 'foregroundcolor',[0 0 0]); • text7=uicontrol(fig1,... • 'Style','text', ... • 'Units','normalized', ... • 'Position',text7pst,... • 'horizontalalignment','center',... • 'FontSize',5, ... • 'FontWeight','light', ... • 'BackgroundColor',ScreenOnColor,... • 'foregroundcolor',[0 0 0]); • text8=uicontrol(fig1,... • 'Style','text', ... • 'Units','normalized', ... • 'Position',text8pst, ... • 'horizontalalignment','center',... • 'FontSize',5, ... • 'FontWeight','light', ... • 'BackgroundColor',ScreenOnColor,... • 'foregroundcolor',[0 0 0]); • text9=uicontrol(fig1,... • 'Style','text', ... • 'Units','normalized', ... • 'Position',text9pst, ... • 'horizontalalignment','center',... • 'FontSize',5, ... • 'FontWeight','light', ... • 'BackgroundColor',ScreenOnColor,... • 'foregroundcolor',[0 0 0]);

  5. text10=uicontrol(fig1,... • 'Style','text', ... • 'Units','normalized', ... • 'Position',text10pst, ... • 'horizontalalignment','center',... • 'FontSize',5, ... • 'FontWeight','light', ... • 'BackgroundColor',ScreenOnColor,... • 'foregroundcolor',[0 0 0]); • text11=uicontrol(fig1,... • 'Style','text', ... • 'Units','normalized', ... • 'Position',text11pst, ... • 'horizontalalignment','center',... • 'FontSize',5, ... • 'FontWeight','light', ... • 'BackgroundColor',ScreenOnColor,... • 'foregroundcolor',[0 0 0]); • text12=uicontrol(fig1,... • 'Style','text', ... • 'Units','normalized', ... • 'Position',text12pst, ... • 'horizontalalignment','center',... • 'FontSize',5, ... • 'FontWeight','light', ... • 'BackgroundColor',ScreenOnColor,... • 'foregroundcolor',[0 0 0]); • text13=uicontrol(fig1,... • 'Style','text', ... • 'Units','normalized', ... • 'Position',text13pst, ... • 'horizontalalignment','center',... • 'FontSize',5, ... • 'FontWeight','light', ... • 'BackgroundColor',ScreenOnColor,... • 'foregroundcolor',[0 0 0]); • text14=uicontrol(fig1,... • 'Style','text', ... • 'Units','normalized', ... • 'Position',text14pst, ... • 'horizontalalignment','center',... • 'FontSize',5, ... • 'FontWeight','light', ... • 'BackgroundColor',ScreenOnColor,... • 'foregroundcolor',[0 0 0]);

  6. % forth static text for label chang %%%%%%%%%%%%%%%%%%%%% • text1m=0.17; • text2m=0.175; • text3m=0.57; • text4pst=[2*left 1-texthigh text1m texthigh-left]; • text5pst=[2*left+text1m 1-texthigh text2m texthigh-left]; • text6pst=[2.8*left+text1m+text2m 1-texthigh text3m texthigh-left]; • textcolor=[0.89 0.89 0.89]; • uicontrol('Style','text', ... • 'Units','normalized', ... • 'FontSize',9, ... • 'FontWeight','bold', ... • 'Position',text4pst, ... • 'BackgroundColor',[0 0 0],... • 'foregroundcolor',textcolor,... • 'string','HLY'); • % five static text for label ps-2000a • text5=uicontrol('Style','text', ... • 'Units','normalized', ... • 'FontAngle','italic', ... • 'FontSize',9, ... • 'FontWeight','light', ... • 'Position',text5pst, ... • 'BackgroundColor',[0 0 0],... • 'foregroundcolor',textcolor,... • 'string','ps-2003B'); • % six static text for label SCIENTIFIC CALCULATOR • text6=uicontrol('Style','text', ... • 'Units','normalized', ... • 'Position',text6pst, ... • 'FontSize',9, ... • 'FontWeight','demi', ... • 'BackgroundColor',[0 0 0],... • 'foregroundcolor',[0.1 1 0.7],... • 'string','SCIENTIFIC CALCULATOR');

  7. %============================================================%============================================================ • % design data for uiconcrol area divide into two groups; • % the one is digit group,and the another is function group. • % • % digit group including 2 frame for undercolor • % 20 frames for pushbottoms • % 20 pushbottoms • % function group inculding 30 frames for undercolor of uicontrol • % 30 pushbottoms • % this design use full of matrix & for loop,since this program is too • % long,and has the same properties between two pushbottom (or frame) • % digit group====================================================== • %--2 frame for undercolor-------------------------- • % basic data • left=0.03; • top=0.745; • bottom=0.03; • border=[insidw insidh -2*insidw -2*insidh]; • frm1pst=[left bottom 1-2*left top-bottom-left]; • frm2pst=frm1pst-border; • frm1color=[0 0 0]; • frm2color=[0.25 0.25 0.25]; • % 1st frame for undercolor • uicontrol('Style','frame', ... • 'Units','normalized', ... • 'Position',frm1pst, ... • 'BackgroundColor',frm1color); • % 2st frame for undercolor • uicontrol('Style','frame', ... • 'Units','normalized', ... • 'Position',frm2pst, ... • 'BackgroundColor',frm2color);

  8. %--20 frames for undercolor of pushbottoms--------------------- • %basic data • spacew=0.03; • spaceh=0.03; • left=frm2pst(1)+spacew; • bottom=frm2pst(2)+spaceh; • width=frm2pst(3); • high=frm2pst(4)/2; • frmwidth=(width-6*spacew)/5; • frmhigh=(high-5*spaceh)/4; • frmcolor1=[0 0 0]; • %calculating all of the frames of (left,bottom) position • frmbottomdh=frmhigh+spaceh; • frmbottom1=bottom*ones(4,1)+... • frmbottomdh*[3 2 1 0]'; • frmbottom=frmbottom1*ones(1,5); • frmleftdw=frmwidth+spacew; • frmleft1=left*ones(1,5)+frmleftdw*[0 1 2 3 4]; • frmleft=ones(4,1)*frmleft1; • for i=1:4 • for j=1:5 • uicontrol('Style','frame', ... • 'Units','normalized', ... • 'Position',... • [frmleft(i,j) frmbottom(i,j) frmwidth frmhigh], ... • 'BackgroundColor',frmcolor1); • end • end

  9. %--20 uicontrols--type pushbuttons--------------------- • %basic data • buttonwidth=frmwidth-1.6*insidw; • buttonhigh=frmhigh-2*insidh; • buttoncolor1=[0.321 0.321 0.321]; • buttonfontcolor1=[1 1 0]; • %calculating all of the frames of (left,bottom) position • buttonleft=frmleft+insidw*ones(4,5); • buttonbottom=frmbottom+0.9*insidh*ones(4,5); • buttontag=ones(4,5); • for i=1:4 • for j=1:5 • buttontag(i,j)=uicontrol(fig1,... • 'Style','push', ... • 'Units','normalized', ... • 'Position',... • [buttonleft(i,j) buttonbottom(i,j)... • buttonwidth buttonhigh], ... • 'FontSize',9, ... • 'FontWeight','bold', ... • 'interruptible','on',... • 'enable','off'); • end • End

  10. set(buttontag(1,1),'string','7',... • 'callback',... • ['a0=''7'';'... • 'calc(''inputdata'',a0)'])%(1,1) • set(buttontag(1,2),'string','8',... • 'callback',... • ['a0=''8'';'... • 'calc(''inputdata'',a0)'])%(1,2) • set(buttontag(1,3),'string','9',... • 'callback',... • ['a0=''9'';'... • 'calc(''inputdata'',a0)'])%(1,3) • set(buttontag(1,4),'string','(',... • 'callback',... • ['a0=''('';'... • 'calc(''inputdata'',a0)'])%(1,4) • set(buttontag(1,5),'string',')',... • 'callback',... • ['a0='')'';'... • 'calc(''inputdata'',a0)'])%(1,5) • set(buttontag(2,1),'string','4',... • 'callback',... • ['a0=''4'';'... • 'calc(''inputdata'',a0)'])%(2,1) • set(buttontag(2,2),'string','5',... • 'callback',... • ['a0=''5'';'... • 'calc(''inputdata'',a0)'])%(2,2) • set(buttontag(2,3),'string','6',... • 'callback',... • ['a0=''6'';'... • 'calc(''inputdata'',a0)'])%(2,3) • set(buttontag(2,4),'string','×',... • 'callback',... • 'calc(''product'')')%(2,4) • set(buttontag(2,5),'string','/',... • 'callback',... • 'calc(''divide'')')%(2,5) • set(buttontag(3,1),'string','1',... • 'callback',... • ['a0=''1'';'... • 'calc(''inputdata'',a0)'])%(3,1) • set(buttontag(3,2),'string','2',... • 'callback',... • ['a0=''2'';'... • 'calc(''inputdata'',a0)'])%(3,2) • set(buttontag(3,3),'string','3',... • 'callback',... • ['a0=''3'';'... • 'calc(''inputdata'',a0)'])%(3,3) • set(buttontag(3,4),'string','+',... • 'callback',... • 'calc(''sum'')')%(3,4) • set(buttontag(3,5),'string','-',... • 'callback',... • 'calc(''difference'')')%(3,5) • set(buttontag(4,1),'string','0',... • 'callback',... • ['a0=''0'';'... • 'calc(''inputdata'',a0)'])%(4,1) • set(buttontag(4,2),'string','.',... • 'callback',... • ['a0=''.'';'... • 'calc(''inputdata'',a0)'])%(4,2) • set(buttontag(4,3),'string','pi',... • 'callback',... • ['a0=''pi'';'... • 'calc(''inputdata'',a0)'])%(4,3) • set(buttontag(4,4),'string','Ans',... • 'callback',... • 'calc(''ans'')')%(4,4),...% Exe key • set(buttontag(4,5),'string','EXE',... • 'callback',... • 'calc(''outputdata'')')%(4,5),...% cls key

  11. %==function group============================================= • %--30 frames for undercolor of pushbottoms--------------------- • %basic data • spacew=0.03; • spaceh=0.025; • left=frm2pst(1)+spacew; • bottom=high+spaceh; • width=frm2pst(3); • high=frm2pst(4)/1.9; • frmwidth=(width-7*spacew)/6; • frmhigh=(high-6*spaceh)/5; • frmcolor1=[0 0 0]; • %calculating all of the frames of (left,bottom) position • frmbottomdh=frmhigh+spaceh; • frmbottom1=bottom*ones(5,1)+... • frmbottomdh*[4 3 2 1 0]'; • frmbottom=frmbottom1*ones(1,6); • frmleftdw=frmwidth+spacew; • frmleft1=left*ones(1,6)+frmleftdw*[0 1 2 3 4 5]; • frmleft=ones(5,1)*frmleft1; • for i=1:5 • for j=1:6 • uicontrol('Style','frame', ... • 'Units','normalized', ... • 'Position',... • [frmleft(i,j) frmbottom(i,j) frmwidth frmhigh], ... • 'BackgroundColor',frmcolor1); • end • end

  12. %--20 uicontrols--type pushbottoms--------------------- • %basic data • buttonwidth=frmwidth-1.6*insidw; • buttonhigh=frmhigh-2*insidh; • buttoncolor1=[0.321 0.321 0.321]; • buttonfontcolor1=[1 1 0]; • buttonleft=frmleft+insidw*ones(5,6); • buttonbottom=frmbottom+0.9*insidh*ones(5,6); • funbuttontag=ones(5,6); • for i=1:5 • for j=1:6 • funbuttontag(i,j)=uicontrol(fig1,... • 'Style','push', ... • 'Units','normalized', ... • 'Position',... • [buttonleft(i,j) buttonbottom(i,j)... • buttonwidth buttonhigh], ... • 'enable','off'); • end • end

  13. set(funbuttontag(1,1),'string','DEG',... • 'callback',... • 'calc(''deg'')') %----------(1,1) • set(funbuttontag(1,2),'string','RAD',... • 'callback',... • 'calc(''rad'')') %----------(1,2) • set(funbuttontag(1,3),'string','GRA',... • 'callback',... • 'calc(''gra'')') %----------(1,3) • set(funbuttontag(1,4),'string','short',... • 'callback',... • 'calc(''short'')') %----------(1,4) • set(funbuttontag(1,5),'string','long',... • 'callback',... • 'calc(''long'')') %----------(1,5) • set(funbuttontag(1,6),'string','Exp',... • 'callback',... • 'calc(''expn'')') %----------(1,6) • set(funbuttontag(2,1),'string','hyp',... • 'callback',... • 'calc(''hyp'')') %----------(2,1) • set(funbuttontag(2,2),'string','inv',... • 'callback',... • 'calc(''inv'')') %----------(2,2) • set(funbuttontag(2,3),'string','sin',... • 'callback',... • 'calc(''psin'')') %----------(2,3) • set(funbuttontag(2,4),'string','cos',... • 'callback',... • 'calc(''pcos'')') %----------(2,4) • set(funbuttontag(2,5),'string','tan',... • 'callback',... • 'calc(''ptan'')') %----------(2,5) • set(funbuttontag(2,6),'string','on',... • 'callback',... • 'calc(''on'')') %----------(2,6) • set(funbuttontag(3,1),'string','^',... • 'callback',... • 'calc(''kaba'')')%----------(3,1) • set(funbuttontag(3,2),'string','sqrt',... • 'callback',... • ['a0=''sqrt('';'... • 'calc(''inputdata'',a0)'])%----------(3,2) • set(funbuttontag(3,3),'string','cub',... • 'callback',... • ['a0=''cub('';'... • 'calc(''inputdata'',a0)'])%----------(3,3)

  14. set(funbuttontag(3,4),'string','ln',... • 'callback',... • ['a0=''log('';'... • 'stra=''ln('';'... • 'calc(''inputdata'',a0,stra)'])%-----(3,4) • set(funbuttontag(3,5),'string','log',... • 'callback',... • ['a0=''log10('';'... • 'stra=''log('';'... • 'calc(''inputdata'',a0,stra)'])%-----(3,5) • set(funbuttontag(3,6),'string','off',... • 'callback',... • 'calc(''off'')') %----------(3,6) • set(funbuttontag(4,1),'string','^2',... • 'callback',... • 'calc(''kaba2'')')%----------(4,1) • set(funbuttontag(4,2),'string','lcm',... • 'callback',... • ['a0=''lcm('';'... • 'calc(''inputdata'',a0)'])%----------(4,2) • set(funbuttontag(4,3),'string','gcd',... • 'callback',... • ['a0=''gcd('';'... • 'calc(''inputdata'',a0)'])%----------(4,3) • set(funbuttontag(4,4),'string','exp',... • 'callback',... • ['a0=''exp('';'... • 'calc(''inputdata'',a0)'])%----------(4,4) • set(funbuttontag(4,5),'string','E',... • 'callback',... • ['a0=''e'';'... • 'calc(''inputdata'',a0)'])%----------(4,5) • set(funbuttontag(4,6),'string','abs',... • 'callback',... • ['a0=''abs('';'... • 'calc(''inputdata'',a0)'])%----------(4,6) • set(funbuttontag(5,1),'string','nPr',... • 'callback',... • ['a0=''nPr('';'... • 'calc(''inputdata'',a0)'])%----------(5,1) • set(funbuttontag(5,2),'string','nCr',... • 'callback',... • ['a0=''nCr('';'... • 'calc(''inputdata'',a0)'])%----------(5,2) • set(funbuttontag(5,3),'string','nHr',... • 'callback',... • ['a0=''nHr('';'... • 'calc(''inputdata'',a0)'])%----------(5,3) • set(funbuttontag(5,4),'string','fact',... • 'callback',... • ['a0=''fact('';'... • 'calc(''inputdata'',a0)'])%----------(5,4) • set(funbuttontag(5,5),'string',',',... • 'callback',... • ['a0='','';'... • 'calc(''inputdata'',a0)'])%----------(5,5) • set(funbuttontag(5,6),'string','Cls',... • 'callback',... • 'calc(''cls'')') %----------------(5,6) • set(funbuttontag(2,6),... • 'enable','on');

  15. % setup initial value in userdata • text=[text1 text2 text3 text4 text5 text6 text7... • text8 text9 text10 text11 text12 text13 text14]; • set(gcf,'userdata',text); • set(text1,'userdata',funbuttontag); • set(text2,'userdata',buttontag); • set(funbuttontag(4,5),'FontWeight','bold') • %================================================= • % Define all of pushbuttons' CallBack • %---------------------------- • % digit group • elseif strcmp(action,'on') • clear • text=get(gcf,'userdata'); • set(text(1),'BackgroundColor',[.6 .9 .3],... • 'string','') • set(text(2),'BackgroundColor',[.6 .9 .3],... • 'string','') • set(text(3),'BackgroundColor',[.6 .9 .3],... • 'string','') • set(text(4),'BackgroundColor',[.375 .505 .225]) • set(text(7),'BackgroundColor',[0.6 0.9 0.3],... • 'foregroundColor',[.6 .9 .3],... • 'string','D') • set(text(8),'BackgroundColor',[0.6 0.9 0.3],... • 'foregroundColor',[.6 .9 .3],... • 'string','R') • set(text(9),'BackgroundColor',[.6 .9 .3],... • 'foregroundColor',[0.6 0.9 0.3],... • 'string','G') • set(text(10),'BackgroundColor',[.6 .9 .3],... • 'foregroundColor',[.6 .9 .3],... • 'string','hyp') • set(text(11),'BackgroundColor',[.6 .9 .3],... • 'foregroundColor',[.6 .9 .3],... • 'string','inv') • set(text(12),'BackgroundColor',[.6 .9 .3],... • 'foregroundColor',[.6 .9 .3],... • 'string','short') • set(text(13),'BackgroundColor',[.6 .9 .3],... • 'foregroundColor',[.6 .9 .3],... • 'string','long') • set(text(14),'BackgroundColor',[.6 .9 .3],... • 'foregroundColor',[.6 .9 .3],... • 'string','Exp') • set(text(8),'BackgroundColor',[0 0 0]) • set(text(12),'BackgroundColor',[0 0 0]) • pause(1.5); • funbuttontag=get(text(1),'userdata'); • buttontag=get(text(2),'userdata');

  16. % setup initial value in userdata • text=[text1 text2 text3 text4 text5 text6 text7... • text8 text9 text10 text11 text12 text13 text14]; • set(gcf,'userdata',text); • set(text1,'userdata',funbuttontag); • set(text2,'userdata',buttontag); • set(funbuttontag(4,5),'FontWeight','bold') • %================================================= • % Define all of pushbuttons' CallBack • %---------------------------- • % digit group • elseif strcmp(action,'on') • clear • text=get(gcf,'userdata'); • set(text(1),'BackgroundColor',[.6 .9 .3],... • 'string','') • set(text(2),'BackgroundColor',[.6 .9 .3],... • 'string','') • set(text(3),'BackgroundColor',[.6 .9 .3],... • 'string','') • set(text(4),'BackgroundColor',[.375 .505 .225]) • set(text(7),'BackgroundColor',[0.6 0.9 0.3],... • 'foregroundColor',[.6 .9 .3],... • 'string','D') • set(text(8),'BackgroundColor',[0.6 0.9 0.3],... • 'foregroundColor',[.6 .9 .3],... • 'string','R') • set(text(9),'BackgroundColor',[.6 .9 .3],... • 'foregroundColor',[0.6 0.9 0.3],... • 'string','G') • set(text(10),'BackgroundColor',[.6 .9 .3],... • 'foregroundColor',[.6 .9 .3],... • 'string','hyp') • set(text(11),'BackgroundColor',[.6 .9 .3],... • 'foregroundColor',[.6 .9 .3],... • 'string','inv') • set(text(12),'BackgroundColor',[.6 .9 .3],... • 'foregroundColor',[.6 .9 .3],... • 'string','short') • set(text(13),'BackgroundColor',[.6 .9 .3],... • 'foregroundColor',[.6 .9 .3],... • 'string','long') • set(text(14),'BackgroundColor',[.6 .9 .3],... • 'foregroundColor',[.6 .9 .3],... • 'string','Exp') • set(text(8),'BackgroundColor',[0 0 0]) • set(text(12),'BackgroundColor',[0 0 0]) • pause(1.5); • funbuttontag=get(text(1),'userdata'); • buttontag=get(text(2),'userdata'); • for i=1:5 • for j=1:6 • set(funbuttontag(i,j),'enable','on') • end • end • for i=1:4 • for j=1:5 • set(buttontag(i,j),'enable','on') • end • end

  17. FalshOn=1;FalshOff=0; • set(text(3),'userdata',FalshOn); • anss=''; • set(text(4),'userdata',anss); • RadMode=2;HypOff=1;InvOff=1; • Mode=[RadMode HypOff InvOff]; • set(text(5),'userdata',Mode) • a='';stra=''; • set(text(7),'userdata',a) • set(text(8),'userdata',stra) • shortMode=-1;ExpMode=4; • set(text(10),'userdata',[shortMode ExpMode]) • calc('cls',a,stra) • % Mode short long expn • elseif strcmp(action,'short')%-----------short--------- • text=get(gcf,'userdata'); • mod=get(text(10),'userdata'); • mod=[-1 mod(2)]; • set(text(10),'userdata',mod) • set(text(12),'BackgroundColor',[0 0 0]) • set(text(13),'BackgroundColor',[.6 .9 .3]) • elseif strcmp(action,'long')%-----------long--------- • text=get(gcf,'userdata'); • mod=get(text(10),'userdata'); • mod=[1 mod(2)]; • set(text(10),'userdata',mod) • set(text(12),'BackgroundColor',[.6 .9 .3]) • set(text(13),'BackgroundColor',[0 0 0]) • elseif strcmp(action,'expn')%-----------expn--------- • text=get(gcf,'userdata'); • mod=get(text(10),'userdata'); • mod=[mod(1) mod(2)*(-1)]; • set(text(10),'userdata',mod) • color=[0 0 0]; • if mod(2)==4 • strexp=''; • color=[.6 .9 .3]; • end • set(text(14),'BackgroundColor',color)

  18. elseif strcmp(action,'hyp')%-----------short--------- • text=get(gcf,'userdata'); • mod=get(text(5),'userdata'); • mod(2)=mod(2)*(-1); • color=[0 0 0]; • if mod(2)==1 • color=[.6 .9 .3]; • end • set(text(5),'userdata',mod) • set(text(10),'BackgroundColor',color) • elseif strcmp(action,'inv')%-----------short--------- • text=get(gcf,'userdata'); • mod=get(text(5),'userdata'); • mod(3)=mod(3)*(-1); • color=[0 0 0]; • if mod(3)==1 • color=[.6 .9 .3]; • end • set(text(5),'userdata',mod) • set(text(11),'BackgroundColor',color)

  19. % Mode DEG,RAD,GRA • elseif strcmp(action,'deg')%-----------DEG--------- • text=get(gcf,'userdata'); • set(text(7),'BackgroundColor',[0 0 0]) • set(text(8),'BackgroundColor',[.6 .9 .3]) • set(text(9),'BackgroundColor',[.6 .9 .3]) • mode=get(text(5),'userdata'); • mode(1)=1; • set(text(5),'userdata',mode) • elseif strcmp(action,'rad')%-------------------RAD------- • text=get(gcf,'userdata'); • set(text(7),'BackgroundColor',[.6 .9 .3]) • set(text(8),'BackgroundColor',[0 0 0]) • set(text(9),'BackgroundColor',[.6 .9 .3]) • mode=get(text(5),'userdata'); • mode(1)=2; • set(text(5),'userdata',mode) • elseif strcmp(action,'gra')%--------------------GRA------ • text=get(gcf,'userdata'); • set(text(7),'BackgroundColor',[.6 .9 .3]) • set(text(8),'BackgroundColor',[.6 .9 .3]) • set(text(9),'BackgroundColor',[0 0 0]) • mode=get(text(5),'userdata'); • mode(1)=3; • set(text(5),'userdata',mode)

  20. elseif strcmp(action,'psin')%-------------------------sin------ • text=get(gcf,'userdata'); • mode=get(text(5),'userdata'); • TypeMode=mode(1);DegMode=1;RadMode=2;GraMode=3; • HypMode=mode(2);HypOn=-1;HypOff=1; • InvMode=mode(3);InvOn=-1;InvOff=1; • if TypeMode==DegMode; • if HypMode==HypOff • if InvMode==InvOff • a0='sind(';stra='sin(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='asind(';stra='asin(';calc('inputdata',a0,stra); • end • elseif HypMode==HypOn • if InvMode==InvOff • a0='sinhd(';stra='sinh(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='asinhd(';stra='asinh(';calc('inputdata',a0,stra); • end • end • elseif TypeMode==RadMode • if HypMode==HypOff • if InvMode==InvOff • a0='sin(';stra='sin(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='asin(';stra='asin(';calc('inputdata',a0,stra); • end • elseif HypMode==HypOn • if InvMode==InvOff • a0='sinh(';stra='sinh(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='asinh(';stra='asinh(';calc('inputdata',a0,stra); • end • end • elseif TypeMode==GraMode • if HypMode==HypOff • if InvMode==InvOff • a0='sing(';stra='sin(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='asing(';stra='asin(';calc('inputdata',a0,stra); • end • elseif HypMode==HypOn • if InvMode==InvOff • a0='sinhg(';stra='sinh(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='asinhg(';stra='asinh(';calc('inputdata',a0,stra); • end • end • end • mode=[mode(1) 1 1]; • set(text(10),'BackgroundColor',[.6 .9 .3]) • set(text(11),'BackgroundColor',[.6 .9 .3]) • set(text(5),'userdata',mode)

  21. elseif strcmp(action,'pcos')%-------------------------cos------ • text=get(gcf,'userdata'); • mode=get(text(5),'userdata'); • TypeMode=mode(1);DegMode=1;RadMode=2;GraMode=3; • HypMode=mode(2);HypOn=-1;HypOff=1; • InvMode=mode(3);InvOn=-1;InvOff=1; • if TypeMode==DegMode; • if HypMode==HypOff • if InvMode==InvOff • a0='cosd(';stra='cos(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='acosd(';stra='acos(';calc('inputdata',a0,stra); • end • elseif HypMode==HypOn • if InvMode==InvOff • a0='coshd(';stra='cosh(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='acoshd(';stra='acosh(';calc('inputdata',a0,stra); • end • end • elseif TypeMode==RadMode • if HypMode==HypOff • if InvMode==InvOff • a0='cos(';stra='cos(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='acos(';stra='acos(';calc('inputdata',a0,stra); • end • elseif HypMode==HypOn • if InvMode==InvOff • a0='cosh(';stra='cosh(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='acosh(';stra='acosh(';calc('inputdata',a0,stra); • end • end • elseif TypeMode==GraMode • if HypMode==HypOff • if InvMode==InvOff • a0='cosg(';stra='cos(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='acosg(';stra='acos(';calc('inputdata',a0,stra); • end • elseif HypMode==HypOn • if InvMode==InvOff • a0='coshg(';stra='cosh(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='acoshg(';stra='acosh(';calc('inputdata',a0,stra); • end • end • end • mode=[mode(1) 1 1]; • set(text(10),'BackgroundColor',[.6 .9 .3]) • set(text(11),'BackgroundColor',[.6 .9 .3]) • set(text(5),'userdata',mode)

  22. elseif strcmp(action,'ptan')%-------------------------tan------ • text=get(gcf,'userdata'); • mode=get(text(5),'userdata'); • TypeMode=mode(1);DegMode=1;RadMode=2;GraMode=3; • HypMode=mode(2);HypOn=-1;HypOff=1; • InvMode=mode(3);InvOn=-1;InvOff=1; • if TypeMode==DegMode; • if HypMode==HypOff • if InvMode==InvOff • a0='tand(';stra='tan(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='atand(';stra='atan(';calc('inputdata',a0,stra); • end • elseif HypMode==HypOn • if InvMode==InvOff • a0='tanhd(';stra='tanh(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='atanhd(';stra='atanh(';calc('inputdata',a0,stra); • end • end • elseif TypeMode==RadMode • if HypMode==HypOff • if InvMode==InvOff • a0='tan(';stra='tan(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='atan(';stra='atan(';calc('inputdata',a0,stra); • end • elseif HypMode==HypOn • if InvMode==InvOff • a0='tanh(';stra='tanh(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='atanh(';stra='atanh(';calc('inputdata',a0,stra); • end • end • elseif TypeMode==GraMode • if HypMode==HypOff • if InvMode==InvOff • a0='tang(';stra='tan(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='atang(';stra='atan(';calc('inputdata',a0,stra); • end • elseif HypMode==HypOn • if InvMode==InvOff • a0='tanhg(';stra='tanh(';calc('inputdata',a0,stra); • elseif InvMode==InvOn • a0='atanhg(';stra='atanh(';calc('inputdata',a0,stra); • end • end • end • mode=[mode(1) 1 1]; • set(text(10),'BackgroundColor',[.6 .9 .3]) • set(text(11),'BackgroundColor',[.6 .9 .3]) • set(text(5),'userdata',mode)

  23. elseif strcmp(action,'sum') • text=get(gcf,'userdata'); • a7=get(text(7),'userdata'); • a8=get(text(8),'userdata'); • a4=get(text(4),'userdata'); • if isempty(a8);a7=a4;a8=a4;end • set(text(7),'userdata',a7) • set(text(8),'userdata',a8) • calc('inputdata','+') • elseif strcmp(action,'difference') • text=get(gcf,'userdata'); • a7=get(text(7),'userdata'); • a8=get(text(8),'userdata'); • a4=get(text(4),'userdata'); • if isempty(a8);a7=a4;a8=a4;end • set(text(7),'userdata',a7) • set(text(8),'userdata',a8) • calc('inputdata','-') • elseif strcmp(action,'product') • text=get(gcf,'userdata'); • a7=get(text(7),'userdata'); • a8=get(text(8),'userdata'); • a4=get(text(4),'userdata'); • if isempty(a8);a7=a4;a8=a4;end • set(text(7),'userdata',a7) • set(text(8),'userdata',a8) • calc('inputdata','*','×') • elseif strcmp(action,'divide') • text=get(gcf,'userdata'); • a7=get(text(7),'userdata'); • a8=get(text(8),'userdata'); • a4=get(text(4),'userdata'); • if isempty(a8);a7=a4;a8=a4;end • set(text(7),'userdata',a7) • set(text(8),'userdata',a8) • calc('inputdata','/') • elseif strcmp(action,'kaba') • text=get(gcf,'userdata'); • a7=get(text(7),'userdata'); • a8=get(text(8),'userdata'); • a4=get(text(4),'userdata'); • if isempty(a8);a7=a4;a8=a4;end • set(text(7),'userdata',a7) • set(text(8),'userdata',a8) • calc('inputdata','^') • elseif strcmp(action,'kaba2') • text=get(gcf,'userdata'); • a7=get(text(7),'userdata'); • a8=get(text(8),'userdata'); • a4=get(text(4),'userdata'); • if isempty(a8);a7=a4;a8=a4;end • set(text(7),'userdata',a7) • set(text(8),'userdata',a8) • calc('inputdata','^2')

  24. %--- action 'cls' • elseif strcmp(action,'cls') • a='';stra='';anss=''; • text=get(gcf,'userdata'); • set(text(7),'userdata',a) • set(text(8),'userdata',stra) • set(text(1),'string',a) • set(text(2),'string',a) • set(text(4),'userdata',anss) • calc('flash',a,stra) • %--- action 'off' • elseif strcmp(action,'off') • text=get(gcf,'userdata'); • funbuttontag=get(text(1),'userdata'); % • buttontag=get(text(2),'userdata'); • ScreenOffColor=[0.35 0.425 0.35]; • BorderOffColor=[0.25 0.288 0.25]; • set(text(1),... • 'BackgroundColor',ScreenOffColor,... • 'string',''); • set(text(2),... • 'BackgroundColor',ScreenOffColor,... • 'string',''); • set(text(3), ... • 'BackgroundColor',ScreenOffColor,... • 'string',''); • set(text(4),... • 'BackgroundColor',BorderOffColor); • set(text(7),'BackgroundColor',ScreenOffColor,... • 'string','') • set(text(8),'BackgroundColor',ScreenOffColor,... • 'string','') • set(text(9),'BackgroundColor',ScreenOffColor,... • 'string','') • pause(0.9); • for i=1:4 • for j=1:5 • set(buttontag(i,j),'enable','off'); • end • end • for i=1:5 • for j=1:6 • set(funbuttontag(i,j),'enable','off'); • end • end • set(funbuttontag(2,6),'enable','on');

  25. elseif strcmp(action,'ans')%----------------action---Ans • text=get(gcf,'userdata'); • anss=get(text(4),'userdata'); • calc('inputdata',anss,'Ans') • elseif strcmp(action,'flash')%--------------action---flash • text=get(gcf,'userdata'); • stra=get(text(8),'userdata'); • ab=' '; • a1='_'; • a3=[ab stra a1]; • [m,n]=size(a3); • a4=a3; • set(text(1),'horizontalalignment','left') • if n>35 • a4=a3(n-34:n); • set(text(1),'horizontalalignment','right') • end • set(text(1),'string',a4) • elseif strcmp(action,'inputdata')%---------action---inputdata • text=get(gcf,'userdata'); • a9=get(text(7),'userdata'); • a=num2str(a9); • str=get(text(8),'userdata'); • a1=[a a0]; • str=[str stra]; • set(text(7),'userdata',a1) • set(text(8),'userdata',str) • calc('flash',a,str) • elseif strcmp(action,'outputdata')%---------action---outputdata • text=get(gcf,'userdata'); • errorflag=0; • a=get(text(7),'userdata'); • if ~isempty(a); • errorflag=eval(a,'1234.567801');%-------------------------------- • if errorflag==1234.567801; • str=[32 lasterr]; • errormsg='Syn ERROR'; • set(text(2),'string',errormsg,... • 'horizontalalignment','center'); • set(text(7),'userdata',''); • set(text(8),'userdata',''); • elseif ~isreal(eval(a)) • errormsg='Not real number'; • set(text(2),'string',errormsg,... • 'horizontalalignment','center'); • set(text(7),'userdata',''); • set(text(8),'userdata',''); • elseif eval(a)>1e300 • set(text(2),'string','inf',... • 'horizontalalignment','right'); • set(text(7),'userdata',''); • set(text(8),'userdata',''); • set(text(4),'userdata','inf'); • elseif 1 • mod=get(text(10),'userdata'); • mod=mod(1)+mod(2); • ans=eval(a);

  26. %for format short • if mod==3 • b=sprintf('%0.5g',ans);b1=b; • end • %for format long • if mod==5 • b=sprintf('%0.8g',ans);b1=b; • end • %for format long e • if mod==-3 • b1=sprintf('%0.8g',ans); • a=ans; • if a>0 • b=sprintf('%0.8g',a); • e_locate=findstr(b,'e'); • if isempty(e_locate) • %type for has not contain e in string b • if a<1 • [m n]=size(b); • b=[b(1) b(3:n)]; • for i=1:n • num=str2num(b(i)); • if num ~=0;break;end; • end • dotp=i-1; • k=num2str(dotp); • ex=['e-00' k]; • b=[b(i) '.' b(i+1:n-1) ex]; • end • dotp=findstr(b,'.'); • if a>10 • if ~isempty(dotp) • [m n]=size(b); • b=[b(1:dotp-1) b(dotp+1:n)]; • if n>9;n=9;end • b=[b(1) '.' b(2:n-1)]; • dotp=dotp-2; • k=num2str(dotp); • ex=['e+00' k]; • b=[b ex]; • else • [m n]=size(b); • if n>8;n=8;end • b=[b(1) '.' b(2:n)]; • dotp=n-1; • k=num2str(dotp); • ex=['e+00' k]; • b=[b ex]; • end • end • if a<10 & a>1 • b=[b 'e000']; • end • end • elseif a=='0'; • b=a; • elseif a<0 • a=-1*a; • b=sprintf('%0.8g',a); • e_locate=findstr(b,'e'); • if isempty(e_locate) • %type for has not contain e in string b • if a<1 • [m n]=size(b); • b=[b(1) b(3:n)]; • for i=1:n • num=str2num(b(i)); • if num ~=0;break;end; • end • dotp=i-1; • k=num2str(dotp); • ex=['e-00' k]; • b=['-' b(i) '.' b(i+1:n-1) ex]; • end • dotp=findstr(b,'.'); • if a>10 • if ~isempty(dotp) • [m n]=size(b); • b=[b(1:dotp-1) b(dotp+1:n)]; • if n>9;n=9;end • b=[b(1) '.' b(2:n-1)]; • dotp=dotp-2; • k=num2str(dotp); • ex=['e+00' k]; • b=['-' b ex]; • else • [m n]=size(b); • if n>8;n=8;end • b=[b(1) '.' b(2:n)]; • dotp=n-1; • k=num2str(dotp); • ex=['e+00' k]; • b=['-' b ex] • end • end • if a<10 & a>1 • b=['-' b 'e000']; • end • else • b=['-' b ]; • end • end • end

  27. %for format short e • if mod==-5 • b1=sprintf('%0.5g',ans); • a=ans; • if a>0 • b=sprintf('%0.5g',a); • e_locate=findstr(b,'e'); • if isempty(e_locate) • %type for has not contain e in string b • if a<1 • [m n]=size(b); • b=[b(1) b(3:n)]; • for i=1:n • num=str2num(b(i)); • if num ~=0;break;end; • end • dotp=i-1; • k=num2str(dotp); • ex=['e-00' k]; • b=[b(i) '.' b(i+1:n-1) ex]; • end • dotp=findstr(b,'.'); • if a>10 • if ~isempty(dotp) • [m n]=size(b); • b=[b(1:dotp-1) b(dotp+1:n)]; • if n>9;n=9;end • b=[b(1) '.' b(2:n-1)]; • dotp=dotp-2; • k=num2str(dotp); • ex=['e+00' k]; • b=[b ex]; • else • [m n]=size(b); • if n>8;n=8;end • b=[b(1) '.' b(2:n)]; • dotp=n-1; • k=num2str(dotp); • ex=['e+00' k]; • b=[b ex]; • end • end • if a<10 & a>1 • b=[b 'e000']; • end • end • elseif a=='0'; • b=a; • elseif a<0 • a=-1*a; • b=sprintf('%0.5g',a); • e_locate=findstr(b,'e'); • if isempty(e_locate) • %type for has not contain e in string b • if a<1 • [m n]=size(b); • b=[b(1) b(3:n)]; • for i=1:n • num=str2num(b(i)); • if num ~=0;break;end; • end • dotp=i-1; • k=num2str(dotp); • ex=['e-00' k]; • b=['-' b(i) '.' b(i+1:n-1) ex ' ']; • end • dotp=findstr(b,'.'); • if a>10 • if ~isempty(dotp) • [m n]=size(b); • b=[b(1:dotp-1) b(dotp+1:n)]; • if n>9;n=9;end • b=[b(1) '.' b(2:n-1)]; • dotp=dotp-2; • k=num2str(dotp); • ex=['e+00' k]; • b=['-' b ex ' ']; • else • [m n]=size(b); • if n>8;n=8;end • b=[b(1) '.' b(2:n)]; • dotp=n-1; • k=num2str(dotp); • ex=['e+00' k]; • b=['-' b ex ' '] • end • end • if a<10 & a>1 • b=['-' b 'e000 ']; • end • else • b=['-' b ' ']; • end • end • end • set(text(2),'string',b,... • 'horizontalalignment','right'); • set(text(7),'userdata',''); • set(text(8),'userdata',''); • set(text(4),'userdata',b1); • end • end • end

  28. %end%last end • %============================================================ • % function group -- for some functions don't exit in MatLab • % • %-----------------------triangle function in degree • function angl=cosd(s) • s=s*pi/180; • angl=cos(s); • function angl=sind(s) • s=s*pi/180; • angl=sin(s); • function angl=tand(s) • s=s*pi/180; • angl=tan(s); • %----------------------- • function angl=acosd(s) • angl=acos(s); • angl=angl*180/pi; • function angl=asind(s) • angl=asin(s); • angl=angl*180/pi; • function angl=atand(s) • angl=atan(s); • angl=angl*180/pi; • %---------------------- • function angl=sinhd(s) • angl=angl*180/pi; • angl=sinh(s); • function angl=coshd(s) • angl=angl*180/pi; • angl=cosh(s); • function angl=tanhd(s) • angl=angl*180/pi; • angl=tanh(s); • %---------------------- • function angl=asinhd(s) • angl=asinh(s); • angl=angl*180/pi; • function angl=acoshd(s) • angl=acosh(s); • angl=angl*180/pi; • function angl=atanhd(s) • angl=atanh(s); • angl=angl*180/pi; • %-----------------------triangle function in GRA • function angl=cosg(s) • s=s*pi/100; • angl=cos(s); • function angl=sing(s) • s=s*pi/100; • angl=sin(s); • function angl=tang(s) • s=s*pi/100; • angl=tan(s); • %----------------------- • function angl=acosg(s) • angl=acos(s); • angl=angl*100/pi; • function angl=asing(s) • angl=asin(s); • angl=angl*100/pi; • function angl=atang(s) • angl=atan(s); • angl=angl*100/pi; • %---------------------- • function angl=sinhg(s) • angl=angl*100/pi; • angl=sinh(s); • function angl=coshg(s) • angl=angl*100/pi; • angl=cosh(s); • function angl=tanhg(s) • angl=angl*100/pi; • angl=tanh(s); • %---------------------- • function angl=asinhg(s) • angl=asinh(s); • angl=angl*100/pi; • function angl=acoshg(s) • angl=acosh(s); • angl=angl*100/pi; • function angl=atanhg(s) • angl=atanh(s); • angl=angl*100/pi; • %---------------------------------- • function ans=nCr(n,r) • ans=fact(n)/fact(n-r)/fact(r); • function ans=nPr(n,r) • ans=fact(n)/fact(n-r); • function ans=nHr(n,r) • ans=fact(n+r-1)/fact(n-1)/fact(r); • function ans=fact(n) • if n<0;error('must be positive');end • if rem(n,1)~=0;error('must be integral');end • if n==0 • ans=1; • else • ans=1; • for i=1:n • ans=ans*i; • end • end • function ans=cub(n) • ans=n^(1/3);

  29. Thank YOU

More Related