matlab 在做gui时,取编辑框的字符串,然后用eval运行为什么会出错?以下是代码
clf;set(gcf,'unit','normalized','position',[0.2 0.3 0.55 0.36]);
set(gcf,'menubar','none','numbertitle','off','name','图形演示');
axes('position',[0.05 0.15 0.55 0.7] );
uicontrol(gcf,'style','text', 'unit','normalized','position',[0.63 0.85 0.2 0.1 ],...
'string','输入绘图命令','horizontal','center');
hedit=uicontrol(gcf,'style','edit','unit',...
'normalized','position',[0.63 0.15 0.2 0.68],'max',2,'horizontal','left');
hpopup=uicontrol(gcf,'style','popup','units','normalized' ,...
'position',[0.85 0.8 0.15 0.15],'string','spring|summer|autumn|winter',...
'call','fun(hedit,hpopup,hlist)');
hlist=uicontrol(gcf,'style','list','units','normalized' ,'string','grid on|grid off|box on|box off','position',...
[0.85 0.55 0.15 0.25 ],'call','fun(hedit,hpopup,hlist)');
hpust1=uicontrol(gcf,'style','push','units','normalized' ,'position',[0.85 0.35 0.15 0.15],'string',...
'绘图','call','fun(hedit,hpopup,hlist)');
uicontrol(gcf,'style','push','units','normalized' ,'position',[0.85 0.15 0.15 0.15],'string','关闭','call','close all');
function fun(a,b,c)
m=get(a,'string');
isstr(m)
n1=get(b,'value');
n2=get(c,'value');
if ~isempty(m)
eval(m);%这里总报错
k={'spring','summer','autumn','winter'};
j={'grid on','grid off','box on','box off'};
colormap(eval(k{n1}));
eval(j{n2});
end