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)