⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exm17.m

📁 电子社08年的《精通MATLABG UI设计》一书的所有代码
💻 M
字号:
clear
clc
PlotSin=[...
'lineSymbols={''.'',''-'',''o'','':'',''x'',''-.'',''--'',''+'',''s'',''d'',''*''};'...
       'k=get(hlist,''Value'');'...                        %获得列表框选中项的value
       'Num=get(hs,''Value'');'...
       'set(heNum,''String'',num2str(Num));'...
        'subplot(ha);'...
         'x=0:0.1:Num*pi;'...
         'plot(x,sin(x),lineSymbols{k});'...             %设置正弦的线型
         'axis([0 Num*pi -1 1]);'...
         'xlabel(''x'');'...
         'ylabel(''y=sin(x)'');'...
         'if get(hcGrid,''Value'')==1;'...                %判断是否选中
         'grid on;'...
        'else;',...
        'grid off;'...
        'end;'...  
         ];
hf=figure('Position',[200 200 600 400] ,...
           'Name','Uicontrol1' ,...
           'NumberTitle','off');
ha=axes('Position',[0.4 0.1 0.5 0.7],...
            'Box','on');
hbSin=uicontrol(hf,...
                'Style','pushbutton',...                     %sin按钮
                'Position',[50,140,100,30],...
                'String','Plot sin(x)',...
                'CallBack',PlotSin);                          %调用PlotSin
hbClose=uicontrol(hf,...
                'Style','pushbutton',...                     %结束按钮
                'Position',[50,100,100,30],...
                'String','Exit',...
                'CallBack','close(hf)'); 
hrboxoff=uicontrol(hf,'Style','radio',...
               'Position',[50 180 100 20],...
               'String','Set box off',...                   %单选按钮off
               'Value',0,...
               'CallBack',[...
                              'set(hrboxon,''Value'',0);'...
                              'set(hrboxoff,''Value'',1);'...
                              'set(gca,''Box'',''off'');']);
hrboxon=uicontrol(hf,'Style','radio',...
                'Position',[50 210 100 20],...
                'String','Set box on',...                   %单选按钮on
                'Value',1,...
                'CallBack',[...
                               'set(hrboxon,''Value'',1);'...
                              'set(hrboxoff,''Value'',0);'...
                              'set(gca,''Box'',''on'');']);   
hcGrid=uicontrol(hf,'Style','check',...                 %复选框
               'Position',[50 240 100 20],...
               'String','Grid on',...
               'Value',1,...
               'CallBack',[...
               'if get(hcGrid,''Value'')==1;'...           %判断是否选中
              'grid on;'...
               'else;'...
              'grid off;'...
              'end;'...
               ]);  
heNum=uicontrol(hf,'Style','edit',...                    %编辑文本框
                  'Position',[50 270 100 20],...
                  'String','4',...
'CallBack','set(heNum,''String'',num2str(Num))');
 htpi=uicontrol(hf,'Style','text',...
                  'Position',[150 270 20 20],...
                  'String','Pi'); 
 htminmax=uicontrol(hf,'Style','text',...               %静态标签
                  'Position',[50 330 100 20],...
                  'String','1pi                 20pi'); 
 hs=uicontrol(hf,'Style','slider',...                     %滑动条
                  'Position',[50 310 100 20],...
                  'value',4,...
                   'Min',1,...
                   'Max',20,...
                   'CallBack',PlotSin);             
hlist=uicontrol(gcf,'Style','list',...                   %列表框
                 'position',[460,330,100,60],...
    'string','.     point|-     solid|o     circle|:     dotted|x     x-mark|-.    dashdot|--    dashed|+     plus|s     square|d     diamond|*     star',...
                 'Max',2,...
                 'CallBack',PlotSin);                           %调用PlotSin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -