简单的pushButton,在MATLAB中更改文本

Mat*_*etz 6 matlab button jbutton

我正在尝试实现一个非常简单的GUI,它只包含一个pushButton.我希望它只是以START作为标签开始.然后按下它变为STOP.当用户第一次将回调设置为true并更改标签时,单击该按钮.第二次单击Button时,布尔值变为false,GUI关闭.

我在MATLAB中找不到任何关于如何制作这样的简单GUI的东西.GUIDE工具对我来说毫无意义,似乎产生了这么多无用的代码.Matlab的按钮是Jbuttons中包装所看到这里

Jon*_*nas 4

GUIDE 非常简单 - 自动化工具为所有回调生成存根,因此剩下的就是填写回调运行时要执行的代码。如果您更喜欢以编程方式创建 GUI,则可以按如下方式创建所需的按钮:

%# create GUI figure - could set plenty of options here, of course
guiFig = figure;

%# create callback that stores the state in UserData, and picks from
%# one of two choices
choices = {'start','stop'};
cbFunc = @(hObject,eventdata)set(hObject,'UserData',~get(hObject,'UserData'),...
          'string',choices{1+get(hObject,'UserData')});

%# create the button
uicontrol('parent',guiFig,'style','pushbutton',...
          'string','start','callback',cbFunc,'UserData',true,...
          'units','normalized','position',[0.4 0.4 0.2 0.2])
Run Code Online (Sandbox Code Playgroud)