MATLAB: GUIDE slider callback within another running callback won’t update handles altered during the slider callback

guide slider handle update

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.

Best Answer

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.