GUI does not recognize existing handles after using addlistener

1 view (last 30 days)
0 down vote favorite
I am quite new to MATLAB GUI programming (using GUIDE sorry) and I have an annoying issue: The GUI displays on an axis an image sequence stored in a cell array. I have a couple of pushbuttons and a slider to scroll through the sequence. In order to get a 'continuous slider' I use a listener object, which kind of works but creates some problems:
1) When I press the slider, a figure is created outside the GUI and the first frame of the sequence is displayed in it, but as I move the slider the sequence is displayed in the axis of my GUI (which is what I want) and the figure becomes empty. Can anybody tell me why this figure is created and how can I avoid it appearing?
2) Once I press the slider button and thus use the listener, all handles inside the GUI are not functionnal as Matlab does not recognize them and I'm stuck with a functionnal slider/display but I can't use the pushbuttons. In other words, it's like only the axis and the slider were in the GUI and every other elements (pushbuttons, text boxes, etc.) were non existent.
Any ideas on why this happens? Here is the code I use in the Create Function of the slider:
function slider_Frame_Video_Callback(hObject, eventdata, handles)
hListener = addlistener(hObject,'ContinuousValueChange',@(a,b) slider2_Frame_Video_Callback(hObject, eventdata, handles)); % a and b are dummy arguments
guidata(hObject,handles)
In the slider callback, the code looks like this (basically imshow in the current axis):
axes(hAxis)
imshow(Movie{frame},'parent',hAxis);
drawnow
% This does not work either as handles.edit_FrameNumber is not recognized by Matlab
set(handles.edit_FrameNumber, 'String', frame);
guidata(hObject,handles);
Thanks a lot for any hints/input!
  2 Comments
Ben11
Ben11 on 2 Jun 2014
- frame is an integer calculated from the position of the slider:
frame = floor(get(hObject,'Value')*NumberFrames) % NumberFrames is the number of images in the cell array.
- Do you mean by attach the whole code for the slider callback?
thanks

Sign in to comment.

Accepted Answer

Sean de Wolski
Sean de Wolski on 2 Jun 2014
Edited: Sean de Wolski on 2 Jun 2014
More than likely the second figure is created because you use one of the get current * functions:
gcf
gca
gco
etc. These functions can't find the GUIDE figure because its 'HandleVisibility' is off and so they create a new one.
  2 Comments
Ben11
Ben11 on 2 Jun 2014
Great the figure does not appear once I remove the code using 'gca' I had a few lines above.
However I used
set(handles.figure1,'HandleVisibility','on')
guidata(hObject,handles);
at the end of the slider callback but I still have the problem about invalid/deleted axes. Is there something I would need to add in the other callbacks of the GUI then?
Ben11
Ben11 on 2 Jun 2014
Hi Sean,
I think I found a workaround for my problem: I changed the callback function in the addlistener definition in order to call an external function, called "ShowCurrentFrame", instead of the slider callback:
Before:
hListener = addlistener(hObject,'ContinuousValueChange',@(a,b) slider2_Frame_Video_Callback(hObject, eventdata, handles));
Now:
hListener = addlistener(hObject,'ContinuousValueChange',@(a,b) ShowCurrentFrame);
Using setappdata/getappdata I load the handles to the slider and I can now call other callbacks from the GUI.
Thanks for your help!

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!