MATLAB Gui,按键上的文本框值没有GUIDE



我有一个没有GUIDE的GUI,只是简单的旧uicontrol,到目前为止我已经让一切正常工作了。然而,我想,按下按钮后,在文本框中获取值(编辑(并将其存储到变量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

最简单的方法是通过输入参数让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个输入参数(的匿名函数,并将s1作为附加参数来调用rotation。回调现在嵌入了句柄s1

最新更新