using button callback in timer
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I'm trying to call a button callback in a timer function, and start it using another button on GUI.
I wrote something like this:
handles.tmr=timer('timerFcn', @Oku_button_Callback(hobject, eventdata, handles), 'Period', 10)
start(handles.tmr);
But this piece of code gives errors like ¨undefined function or variable 'hobject'¨ and ¨error while evaluating TimerFcn for timer 'timer-2' ¨
Is there any solutions you know?
Thanks
Furkan.
0 Kommentare
Antworten (1)
Jan
am 30 Jul. 2012
Bearbeitet: Jan
am 30 Jul. 2012
Correct syntax:
handles.tmr = timer('timerFcn', {@Oku_button_Callback, handles}, 'Period', 10)
When the function handle appears in a cell, the first two arguments ObjectHandle and EventData are inserted automatically. Be aware, that the timer's handle is provided to the button's callback, such that you need to address the button using handles instead of ObjectHandle.
2 Kommentare
Jan
am 30 Jul. 2012
furkan kilic wrote (please post comments as comments, not as new answer):
Thanks for the answer Jan.
Your code works just for one cycle, then it gives two errors: 'Error while evaluating TimerFcn for timer 'timer-2' ' and 'H must be the handle to a figure or figure descendent'
Also, I could now exactly understand your advice.
Jan
am 30 Jul. 2012
Please note, that I do not know your code. Therefore I have no idea what "one cycle" means, nor why or where this error occurs.
Usually the first input of a callback is a handle to the calling object. When you call the callback of a button from a timer, you cannot rely on handles = guidata(hObject) or however your 1st input is called. But it is possible to insert the required handle to the handles struct provided as 3rd input of the callback. To learn more about callbacks, reading the corresponding documentation is recommended: docsearch callback
If you want us to solve your current problem, post the relevant part of the code and a complete error message. Please add this by editing the original question after a "[EDITED]" tag, and not as comment or answer, such that after reading your question, a user can decide, if (s)he can give a useful answer.
Siehe auch
Kategorien
Mehr zu Code Execution finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!