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

1 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2019-11-14
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by