h0 = figure('toolbar','none',... 'position',[200 150 450 250],... 'name','gui_mytry',... 'numbertitle','off'); x = 0:0.5:2*pi; y = sin(x); h = plot (x,y); grid on; hm = uicontrol(h0,'style','text',... 'string','绘图函数',... 'position',[380 180 50 20]); hm =uicontrol(h0,'style','popupmenu',... 'string',... 'sin(x)|cos(x)|sin(x)+cos(x)',... 'position',[380 150 50 20]); set(hm,'value',1) my_callback = [... 'v=get(hm,"value");,',... 'switch v,',... 'case 1,',... 'delete(h),',... 'y = sin(x);,',... 'h = plot(x,y);,',... 'grid on,'... 'case 1,',... 'delete(h),',... 'y = sin(x);,',... 'h = plot(x,y);,',... 'grid on,'... 'case 2,',... 'delete(h),',... 'y = cos(x);,',... 'h = plot(x,y);,',... 'grid on,'... 'case 3,',... 'delete(h),',... 'y = sin(x)+cos(x);,',... 'h = plot(x,y);,',... 'grid on,'... 'end']; set(hm,'callback',my_callback); set(gca,'position',[0.2 0.2 0.6 0.6]);
function[] = example(); S.fh=figure('units','normalized',... 'position',[0.1 0.1 0.3 0.3],... 'menubar','none',... 'name','exmaple',... 'numbertitle','off',... 'resize','off'); S.text=uicontrol('style','text',... 'unit','normalized',... 'position',[0.1 0.85 0.4 0.05],... 'string','change color'); S.pop=uicontrol('style','popupmenu',... 'unit','normalized',... 'position',[0.6 0.8 0.3 0.1],... 'string',{'red';'green';'blue';... 'yellow';'black';'cyan';'magenta'}); S.axes = axes('unit','normalized',... 'position',[0.1 0.1 0.8 0.7]); x=0:pi/50:8*pi; y=sin(x); axes(S.axes); S.hplot=plot(x,y,'color',[1 0 0]); set(S.pop,'callback',{@mycallback,S}); function mycallback(obj,event,S) val = get(obj,'Value'); switch val case 1 set(S.hplot,'color',[1 0 0]); case 2 set(S.hplot,'color',[0 1 0]); case 3 set(S.hplot,'color',[0 0 1]); case 4 set(S.hplot,'color',[1 1 0]); case 5 set(S.hplot,'color',[0 0 0]); case 6 set(S.hplot,'color',[0 1 1]); case 7 set(S.hplot,'color',[1 0 1]); end
来源:博客园
作者:coolwx
链接:https://www.cnblogs.com/coolwx/p/11427400.html