GUI does not recognize existing handles after using addlistener
1 view (last 30 days)
Show older comments
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
Accepted Answer
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.
More Answers (0)
See Also
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!