Run pushbutton automatically as soon as the GUI is visible without pressing the pushbutton

1 visualizzazione (ultimi 30 giorni)
I want to run my pushbutton automatically as soon as the GUI is visible. And dont have to press the pushbutton in order to start the pushbutton. I only want the pushbutton to be started once. Can i get any help? Im new to MATLAB and i have searched but cannot find my answer.
Thankyou in advance.

Risposta accettata

Walter Roberson
Walter Roberson il 14 Nov 2019
In the OpenFcn callback, create a timer object configured for a single execution, and have the callback for the timer object be a call to the name of the callback for the pushbutton, passing in the handle of the pushbutton, then [], and then the handles variable. But do it like this:
handles.push_timer = timer(... various arguments ...);
guidata(hObject, handles); %store a copy of handles complete with the push_timer
handles.push_timer.TimerFcn = @(hObject, event) YourGUI_pushbutton1_Callback(handles.pushbutton1, [], handles);
start(handles.push_timer)
That is, do not set the TimerFcn callback to refer to handles until after you have already stored the timer object in handles. The timer() function permits you to configure TimerFcn as an option at the time you create the timer, but do not do that. If you do that, then the value of handles that makes it into the callback will not include the timer object and you would risk the timer being deleted before it gets used.

Più risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by