how to automatically click a pushbutton continously

15 次查看(过去 30 天)
for a gui project i want to click a pushbutton automatically after every 1 second...please provide code...... my code is
t=clock;
c=fix(t);
v=c(1,4);
b=c(1,5);
set(handles.text2,'string',[v,b]);
set(handles.text3,'string',[v,b+30]);
now how to run set function after every 1 second without clicking pushbutton manually

采纳的回答

Geoff Hayes
Geoff Hayes 2016-9-27
Prasanna - if you want to periodically perform an action, then use a timer. In the OpeningFcn of your GUI, you would create the timer, add the handle to the timer to the handles structure, and then start the timer as
% create the timer
handles.timer = timer('Name','MyTimer', ...
'Period',1, ...
'StartDelay',0, ...
'TasksToExecute',inf, ...
'ExecutionMode','fixedSpacing', ...
'TimerFcn',{@timerCallback,handles.figure1});
% Update handles structure
guidata(hObject, handles);
start(handles.timer);
Note that the above timer has a period of one second and that every second the timerCallback function will fire. The body for this callback would be
function timerCallback(hObject,event,hFigure)
handles = guidata(hFigure);
if ~isempty(handles)
t=clock;
c=fix(t);
v=c(1,4);
b=c(1,5);
set(handles.text1,'String',sprintf('%d:%d:%d',v,b, c(1,6)));
set(handles.text2,'String',sprintf('%d:%d:%d',v,b, c(1,6)));
end
The third input to this function is the handle to the figure/GUI (which is set when the timer callback is initialized). We use it to get the handles structure so that we have access to the text fields that we wish to update. It wasn't clear to me what v and b are (or why you add 30 to the hour (?)), so I just used sprintf to create a string with the current time as HH:MM:SS.
When the user closes the GUI, the CloseRequestFcn is called and it stops the timer.
See the attached for an example (created with R2014a).
  5 个评论
Geoff Hayes
Geoff Hayes 2016-9-29
Prasanna - if I run your code from the command line as
>> PRA
I do not observe any errors. However, if I double-click the PRA.fig file then I see the same error message as your. This is expected. GUIDE created GUIs can only be opened/launched from the command line (like I did above) or by pressing the run button in either the GUIDE editor or m-file editor. You cannot launch a GUI by double-clicking on the fig file.
Prasanna kulkarni
Prasanna kulkarni 2017-9-22
How to add images in front of countries in above program. Please explain with above example.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Entering Commands 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by