资源描述:
《Matlab界面设计的例子》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、1、很简单,在界面上放三个单选按钮控制颜色(R、G、B),四个pushbutton(功能分别为绘制正弦、余弦、gridoff、退出程序),可作为一个小小的入门。程序为:%simpleGUI2.m-asimpleuseofRadiobuttonandPushbuttonclearall;FigWin=figure('Position',[100,100,600,300],'Name','Uicontrol:PushButton&RadioButton',...'NumberTitle','off');AxesHandle=axes('Position',[0.4,
2、0.15,0.5,0.8],'Box','on'); RadioNum=3;fori=1:RadioNumRadio(i)=0;%initialvalue=0end Radio(1)=uicontrol(FigWin,...%父对象FigWin(一figure对象),备注③'Style','Radio',...'Position',[5025510030],...'String','DrawinRed',...'CallBack',...['n=1;'...'ifget(Radio(1),''Value'')==1;'...%要使各radiobutton之间具有
3、互斥性,要用if...else语句'set(Radio([1:(n-1),(n+1):RadioNum]),''Value'',0);'...'else;'...%要加上分号,一种规定?参备注①'set(Radio(1),''Value'',1);'...'end;'...'ColorStr=''r'';'...'set(FunHandle,''Color'',''red'')']);%曲线颜色根据radiobutton的选项实时变化,ColorStr是一个全局变量 Radio(2)=uicontrol(FigWin,...'Style','Radio',...
4、'Position',[5021510030],...'String','DrawinGreen',...'CallBack',...['n=2;'...'ifget(Radio(2),''Value'')==1;'...'set(Radio([1:(n-1),(n+1):RadioNum]),''Value'',0);'...'else;'...'set(Radio(2),''Value'',1);'...'end;'...'ColorStr=''g'';'...'set(FunHandle,''Color'',''green'')']); Radio(3)=
5、uicontrol(FigWin,...'Style','Radio',...'Position',[5017510030],...'String','DrawinBlue',...'CallBack',...['n=3;'...'ifget(Radio(3),''Value'')==1;'...'set(Radio([1:(n-1),(n+1):RadioNum]),''Value'',0);'...'else;'...'set(Radio(3),''Value'',1);'...'end;'...'ColorStr=''b'';'...'set(FunHan
6、dle,''Color'',''blue'')']); push1=uicontrol(FigWin,...'Style','pushbutton',...'Position',[5013510030],...'String','Plotsin(x)',...'CallBack',...['subplot(AxesHandle);'...%注意父对象是AxesHandle而非FigWin!参备注②'x=0:.1:4*pi;'...'FunHandle=plot(x,sin(x),ColorStr);'...%ColorStr变量的值受radiobutton控制'
7、axis([04*pi-11]);'...'gridon;'...'xlabel(''x'');'...'ylabel(''y=sin(x)'');']); push2=uicontrol(FigWin,...'Style','pushbutton',...'Position',[509510030],...'String','Plotcos(x)',...'CallBack',...['subplot(AxesHandle);'...'x=0:.1:4*pi;'...'FunHandle=plot(x,cos(x),ColorStr);'...'axis([0
8、4*pi-11]);'.