1

我有一个没有 GUIDE 的 GUI,只是普通的旧 uicontrols,到目前为止我已经让一切正常工作。但是我想,在按下按钮后,在文本框(编辑)中获取值并将其存储到变量 fi 中。

基本上是有问题的代码;

c2 = uicontrol(f,'Style', 'pushbutton','String','Rotation','Callback', 
@rotation);
s1 = uicontrol(f,'Style', 'edit');

function rotation(src,event)
   load 'BatMan.mat' X
   fi = %This is the value I want to have the value as the edit box.
   subplot(2,2,1)
   PlotFigure(X)
end
4

1 回答 1

1

最简单的方法是通过输入参数rotation了解:s1

c2 = uicontrol(f,'Style', 'pushbutton','String','Rotation');
s1 = uicontrol(f,'Style', 'edit');
set(c2,'Callback',@(src,event)rotation(s1,src,event));

function rotation(s1,src,event)
   load 'BatMan.mat' X
   fi = get(s1,'String');
   subplot(2,2,1)
   PlotFigure(X)
end

在这里,我们将回调设置为c2具有正确签名(2 个输入参数)的匿名函数,并rotation作为s1附加参数调用。回调现在s1嵌入了句柄。

于 2018-11-17T00:03:39.237 回答