资源描述:
《matlab课件:用户界面设计2》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、例1建立控件对象,当单击该按钮时绘制出正弦曲线。同时建立双位按钮,用于绘制是否给坐标加网格线。建立单选按钮,用来设置图形窗口的颜色,只能选一种颜色。123functionpushbutton1_Callback(hObject,eventdata,handles)t=0:pi/20:2*pi;handles.current_data=plot(t,sin(t));axis([02*pi-11]);4functionpushbutton2_Callback(hObject,eventdata,handles)if(get(hObj
2、ect,'Value')==1)gridon;elsegridoff;end5functionradiobutton1_Callback(hObject,eventdata,handles)%hObjecthandletoradiobutton1(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)h2=findobj(gcf,'String','white
3、');set(h2,'Value',0);h3=findobj(gcf,'String','blue');set(h3,'Value',0);if(get(hObject,'Value')==1)set(gcf,'Color','r');end6functionradiobutton2_Callback(hObject,eventdata,handles)%hObjecthandletoradiobutton2(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMAT
4、LAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)h2=findobj(gcf,'String','red');set(h2,'Value',0);h3=findobj(gcf,'String','blue');set(h3,'Value',0);if(get(hObject,'Value')==1)set(gcf,'Color','w');end7functionradiobutton3_Callback(hObject,eventdata,handles)%hObje
5、cthandletoradiobutton3(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)h2=findobj(gcf,'String','red');set(h2,'Value',0);h3=findobj(gcf,'String','white');set(h3,'Value',0);if(get(hObject,'Value')==1)set(
6、gcf,'Color','b');end8例2建立如图8.10所示的“数制转换”对话框。在左边输入一个十进制整数和2~16之间的数,单击“转换”按钮能在右边得到十进制对应的2~16进制字符串,单击“退出”按钮退出对话框。pushbuttoneditFrameText910functionex8p10_OpeningFcn(hObject,eventdata,handles,varargin)%Thisfunctionhasnooutputargs,seeOutputFcn.%hObjecthandletofigure%event
7、datareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%varargincommandlineargumentstoex8p10(seeVARARGIN)globalnb11functionedit1_Callback(hObject,eventdata,handles)%hObjecthandletoedit1(seeGCBO)%eventdatareserved-tobedefine
8、dinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)globalnn=str2double(get(hObject,'String'));12functioned