popup按钮如何调用不同的函数
hpop=uicontrol(h_main,'style','popup',...'position',,...
'string','无|sin(x)|cos(x)|tan(x)',...
'callback',******** ); 这里的调用如何编写啊,下拉popup按钮后,选择sin(x),就调用了sin(x)绘图 ,选择cos(x),就调出cos(x)的图啊,x已经定义了
请指教 原帖由 plsdd 于 2006-12-20 10:48 发表
hpop=uicontrol(h_main,'style','popup',...
'position',,...
'string','无|sin(x)|cos(x)|tan(x)',...
'callback',******** ); 这里的调用如何编写啊,下拉popup按钮 ...
'callback',@myfunc);
......
function myfunc(hObject,eventdata,handles)
switch get('hObject','Value')
case 1
sin(x)%这里自己写想要的函数
case 2
cos(x)
case 3
tan(x)
end
上面代码自己试试吧,我这里没有matlab,不能保证完全正确 对这个不太熟
??? Error while evaluating uicontrol Callback
??? Undefined function or variable 'hpop'.
Error in ==> timeRE>myfunc at 107
switch get(hpop,'Value')
hpop怎么传不进来啊,是不是要在最开始定义全局变量? h0=figure('toolbar','none',...
'position',,...
'name','实例36');
x=0:0.5:2*pi;
y=sin(x);
h=plot(x,y);
grid on
hm=uicontrol(gcf,'style','popupmenu',...
'string',...
'sin(x)|cos(x)|sin(x)+cos(x)|exp(-sin(x))',...
'position',);
set(hm,'value',1)
huidiao=[...
'v=get(hm,''value'');,',...
'switch v,',...
'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,',...
'case 4,',...
'delete(h),',...
'y=exp(-sin(x));,',...
'h=plot(x,y);,',...
'grid on,',...
'end'];
set(hm,'callback',huidiao)
set(gca,'position',)
title('弹出式菜单的使用') 呵呵,谢谢老八和jimin(纪敏?),又知道个东西了 原帖由 plsdd 于 2006-12-20 11:50 发表
对这个不太熟
??? Error while evaluating uicontrol Callback
??? Undefined function or variable 'hpop'.
Error in ==> timeRE>myfunc at 107
switch get(hpop,'Value')
hpop怎么传不进来啊 ...
敲错了,我想应该是 get(hObject,'value'),呵呵。不好意思,没有matlab,不能运行
页:
[1]