MATLAB Gui,在没有GUIDE的情况下按下按钮时的文本框值

时间:2018-11-16 23:30:01

标签: matlab matlab-gui

我有一个没有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

1 个答案:

答案 0 :(得分: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

相关问题