紧急求助!关于matlab中GUI用户图形界面通过edit输入调用函数问题!
是可以的,可以见张志涌《精通matlab6.5版》的一个例子:(图片中的绘图指令输入框就是你说的命令输入框,可以参考这个例子,实现你的功能,主要是eval的使用,用法你可以查看eval的帮助)
【例10.4.3.3-1】目标:制作一个能绘制任意图形的交互界面。它包括:可编辑文本框、弹出框、列表框。本例的关键内容是:如何使编辑框允许输入多行指令。
[exm100433_1.m]
clf reset % <1>
set(gcf,'unit','normalized','position',[0.1,0.4,0.85,0.35]);
set(gcf,'defaultuicontrolunits','normalized');
set(gcf,'defaultuicontrolfontsize',11);
set(gcf,'defaultuicontrolfontname','隶书');
set(gcf,'defaultuicontrolhorizontal','left');
set(gcf,'menubar','none');
str='通过多行指令绘图的交互界面';
set(gcf,'name',str,'numbertitle','off');
h_axes=axes('position',[0.05,0.15,0.45,0.70],'visible','off');
uicontrol(gcf,'Style','text',...
'position',[0.52,0.87,0.26,0.1],...
'String','绘图指令输入框');
hedit=uicontrol(gcf,'Style','edit',... % <14>
'position',[0.52,0.05,0.26,0.8],...
'Max',2); % <16>
hpop=uicontrol(gcf,'style','popup',... % <17>
'position',[0.8,0.73,0.18,0.12],...
'string','spring|summer|autumn|winter');% <19>
hlist=uicontrol(gcf,'Style','list',... % <20>
'position',[0.8,0.23,0.18,0.37],...
'string','Grid on|Box on|Hidden off|Axis off',...% <22>
'Max',2); % <23>
hpush=uicontrol(gcf,'Style','push',... % <24>
'position',[0.8,0.05,0.18,0.15],'string','Apply');
set(hedit,'callback','calledit(hedit,hpop,hlist)'); % <26>
set(hpop,'callback','calledit(hedit,hpop,hlist)'); % <27>
set(hpush,'callback','calledit(hedit,hpop,hlist)'); % <28>
[calledit.m]%这个是子函数
function calledit(hedit,hpop,hlist)
ct=get(hedit,'string'); % <2>
vpop=get(hpop,'value'); % <3>
vlist=get(hlist,'value'); % <4>
if ~isempty(ct) % <5>
eval(ct') % <6>
popstr={'spring','summer','autumn','winter'}; % <7>
liststr={'grid on','box on','hidden off','axis off'};% <8>
invstr={'grid off','box off','hidden on','axis on'};% <9>
colormap(eval(popstr{vpop})) % <10>
vv=zeros(1,4);vv(vlist)=1;
for k=1:4
if vv(k);eval(liststr{k});else eval(invstr{k});end
end
end