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

2 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Walter Roberson
Walter Roberson le 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.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by