资源描述
单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,例,1,建立控件对象,当单击该,按钮,时绘制出正弦曲线。同时建立,双位按钮,,用于绘制是否给坐标加网格线。,建立,单选按钮,,用来设置图形窗口的颜色,只能选一种颜色。,1,2,3,function,pushbutton1_Callback,(hObject,eventdata,handles),t=0:pi/20:2*pi;,handles.current_data,=,plot(t,sin(t,);,axis(0 2*pi-1 1);,4,function,pushbutton2_Callback,(hObject,eventdata,handles),if(,get(hObject,Value)=1),grid on;,else,grid off;,end,5,function,radiobutton1_Callback,(hObject,eventdata,handles),%,hObject,handle to radiobutton1(see GCBO),%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),h2=,findobj(gcf,String,white,);,set(h2,Value,0);,h3=,findobj(gcf,String,blue,);,set(h3,Value,0);,if (,get(hObject,Value,)=1),set(gcf,Color,r,);,end,6,function,radiobutton2_Callback,(hObject,eventdata,handles),%,hObject,handle to radiobutton2(see GCBO),%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),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,);,end,7,function,radiobutton3_Callback,(hObject,eventdata,handles),%,hObject,handle to radiobutton3(see GCBO),%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),h2=,findobj(gcf,String,red,);,set(h2,Value,0);,h3=,findobj(gcf,String,white,);,set(h3,Value,0);,if(,get(hObject,Value,)=1),set(gcf,Color,b,);,end,8,例,2,建立如图,8.10,所示的“数制转换”对话框。在左边输入一个十进制整数和,2,16,之间的数,单击“转换”按钮能在右边得到十进制对应的,2,16,进制字符串,单击“退出”按钮退出对话框。,pushbutton,edit,Frame,Text,9,10,function ex8p10_,OpeningFcn,(hObject,eventdata,handles,varargin,),%This function has no output,args,see,OutputFcn,.,%,hObject,handle to figure,%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),%,varargin,command line arguments to ex8p10(see VARARGIN),global n b,11,function,edit1_Callback,(hObject,eventdata,handles),%,hObject,handle to edit1(see GCBO),%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),global n,n=str2double(get(hObject,String);,12,function,edit2_Callback,(hObject,eventdata,handles),%,hObject,handle to edit2(see GCBO),%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),global b,b=str2double(get(hObject,String);,%Hints:,get(hObject,String,)returns contents of edit2 as text,%str2double(get(hObject,String)returns contents of edit2 as a double,13,function,pushbutton1_Callback,(hObject,eventdata,handles),%,hObject,handle to pushbutton1(see GCBO),%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),global n b,h=findobj(gcf,Tag,edit3);,dec,=,trdec(n,b);,set(h,String,dec,);,14,function,pushbutton2_Callback,(hObject,eventdata,handles),%,hObject,handle to pushbutton2(see GCBO),%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),close(gcf,);,15,16,17,例,3,建立如图,8.11,所示的图形演示对话框。在文本框中输入绘图命令,当单击“绘图”按钮时,能在左边坐标轴所对应的图形,下拉列表框提供色图控制,列表框提供坐标网格线和坐标边框控制。,Popup button,edit,listbox,Axis,pushbutton,18,19,function,popupmenu1_Callback,(hObject,eventdata,handles),%,hObject,handle to popupmenu1(see GCBO),%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),n1=,get(hObject,Value);,chpop,=,spring,summer,autumn,winter,;,colormap(eval(chpopn1);,20,function,pushbutton1_Callback,(hObject,eventdata,handles),%,hObject,handle to pushbutton1(see GCBO),%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),21,function,edit1_Callback,(hObject,eventdata,handles),%,hObject,handle to edit1(see GCBO),%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),hedit,=,get(hObject,String,);,eval(hedit,),22,function,listbox1_Callback,(hObject,eventdata,handles),%,hObject,handle to listbox1(see GCBO),%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),n2=,get(hObject,Value);,chlist,=grid,on,grid,off,box,on,box,off;,eval(chlistn2);,23,function,pushbutton2_Callback,(hObject,eventdata,handles),%,hObject,handle to pushbutton2(see GCBO),%,eventdata,reserved-to be defined in a future version of MATLAB,%handles structure with handles and user data(see GUIDATA),close all;,24,25,26,27,28,29,30,
展开阅读全文