Simple button with changing text in MATLAB

I am trying to implement a very simple graphical interface consisting of just one pushButton. I want it to start with START being like a label. Then, when pressed, it goes to STOP. When the user clicks the button, the first time the callback sets the boolean value true and changes the label. When the button is pressed a second time, the logical value is changed to false, and the graphical interface closes.

I can not find anything about how to make a simple graphical interface like this in MATLAB. the GUIDE tool makes no sense to me and seems to generate so much useless code. Matlab buttons are wrappers for jButtons, as shown here

+6
source share
1 answer

GUIDE is pretty simple - the automated tool generates stubs for all callbacks, so all is left is to fill in the code that will be executed whenever the callback is executed. If you want to programmatically create a graphical interface, you can create the desired button as follows:

%# 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]) 
+4
source

All Articles