GUIDE slider callback within another running callback won't update handles altered during the slider callback
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jian Zhou
am 25 Jul. 2017
Kommentiert: Jian Zhou
am 25 Jul. 2017
Hi everyone,
i am currently working on a GUI for a program i have written in Matlab and have come across a problem where i just can't figure out how to resolve it. Researches didn't really help for my specific case. I hope someone here can help me out.
So basically, my GUI has one start pushbutton, when pressed, my program will be started in the pushbutton_Callback. The .m-file contains a for-loop to subsequently display video frames on a axes in the GUI. So it basically looks like a video player, and the code processes some information on the individual frames and displays the results on the frames right away. Now i am trying to add a slide bar, which the user can operate on, even when the pushbutton_Callback is still running. What i am looking for is, when the slide bar is operated during pushbutton_Callback, the slider_Callback should output a handle called handles.slider_moved (value = 1) and the pushbutton_Callback picks up this changed handle and terminates its execution by the use of return. Now the problem is, that the handle slider_moved doesn't get updated after the slider_Callback has finished running (local scope within the slider_Callback), so the "if handles.slider_moved" condition is never met in the pushbutton_Callback(see belowing example code):
function pushbutton_Callback(hObject,eventdata,handles)
handles.slider_moved = 0;
for i = currentFrame:totalFrame
...
if handles.slider_moved
return;
end
end
function slider_Callback(hObject,eventdata,handles)
handles.slider_moved = 1;
calculate frame number corresponding to the new slider value...
guidata(hObject,handles)
I tried
function handles = slider_Callback(hObject,eventdata,handles)
and it didn't change anything.
What i want in the end is the following:
when slide bar is moved during video play (meaning pushbutton_Callback still running), play the video starting from the frame/time corresponding to the new position of the slider. And terminating the current pushbutton_Callback is the first step in doing so.
I'm grateful for any kind of advices. If there are better methods to achieve the end goal, please enlighten me!
Thanks alot in advance.
2 Kommentare
Adam
am 25 Jul. 2017
Bearbeitet: Adam
am 25 Jul. 2017
The handles are being updated in the GUI, the problem is that the handles in the pushbutton callback are local, not the handles in the slider callback.
You may be able to fix it just by putting
for i = currentFrame:totalFrame
...
handles = guidata( hObject )
if handles.slider_moved
return;
end
end
in your pushbutton callback but if you are also adding things to handles in the pushbutton callback that will not work out either as they will just get lost.
In terms of 'better' methods, I would favour using classes and listeners to achieve this kind of thing, but that is too complicated to explain right now!
Akzeptierte Antwort
Jan
am 25 Jul. 2017
Bearbeitet: Jan
am 25 Jul. 2017
function handles = slider_Callback(hObject,eventdata,handles)
No, callbacks do not have output arguments.
If you change the contents of the handles struct, update it by retrieving it from the fuigure inside the loop:
handles.slider_moved = 0;
for i = currentFrame:totalFrame
...
handles = guidata(hObject); % Get current value
if handles.slider_moved
return;
end
end
Note that each function has its own copy of the handles struct, until you reload the value from the figure again.
3 Kommentare
Adam
am 25 Jul. 2017
You should never be manually calling a callback from somewhere. Put the code into a separate function to be called from multiple places if you wish to do this, but you shouldn't having to crowbar in the input arguments that a callback wants rather than the arguments your actual code wants.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps 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!