slider - Using addlister in MATLAB GUI seems to "delete" existing handles -
i quite new matlab gui programming (using guide sorry) , have following issue: gui displays on axis image sequence stored in cell array. have couple of pushbuttons , slider scroll through sequence. in order 'continuous slider' use listener, kind of works creates problems:
1) when press slider, figure created , first frame of sequence displayed in it, move slider sequence displayed in axis of gui (which want) , figure becomes empty. can tell me why figure created , how can avoid it?
2) once press slider button , use listener, handles inside gui not functionnal matlab not recognize them , i'm stuck functionnal slider/display can't use pushbuttons.
any ideas on why happens? here code use in create function of slider:
function slider2_frame_video_callback(hobject, eventdata, handles) hlistener = addlistener(hobject,'continuousvaluechange',@(a,b) slider2_frame_video_callback(hobject, eventdata, handles)); % , b dummy arguments guidata(hobject,handles)
in slider callback, code looks (basically imshow in current axis):
axes(haxis) imshow(movie{frame},'parent',haxis);
drawnow
% not work either handles.edit_framenumber not recognized matlab
set(handles.edit_framenumber, 'string', frame); guidata(hobject,handles);
any hints welcome thanks!
i wonder if part of problem listener being instantiated each time user moves slider since listener code within callback , callback being provided listener (seems kind of strange back-and-forth there). every time user releases mouse button after slide, new listener created. may causing problems other buttons not being responsive.
rather instantiating listener there, in opening_fcn
of gui:
% --- executes before frameslider made visible. function frameslider_openingfcn(hobject, eventdata, handles, varargin) % function has no output args, see outputfcn. % hobject handle figure % eventdata reserved - defined in future version of matlab % handles structure handles , user data (see guidata) % varargin command line arguments frameslider (see varargin) % choose default command line output frameslider handles.output = hobject; if ~isfield(handles,'hlistener') handles.hlistener = ... addlistener(handles.slider1,'continuousvaluechange',@respondtocontslidecallback); end % update handles structure guidata(hobject, handles);
my gui named frameslider
; yours else. above creates 1 listener callback function need define in same *.m file, respondtocontslidecallback
.
a sample body callback respond continuous slide is
% --- executes on slider movement. function respondtocontslidecallback(hobject, eventdata) % hobject handle slider1 (see gcbo) % eventdata reserved - defined in future version of matlab % hints: get(hobject,'value') returns position of slider % get(hobject,'min') , get(hobject,'max') determine range of slider % first need handles structure can hobject handles = guidata(hobject); % test display current value along slider disp(['at slider coordinate ' num2str(get(hobject,'value'))]);
if run code, command window display continuously slider coordinate move slider end end.
your above code has movies
cell array. how being accessed callback? global variable or ..? hist
come from? if movies
result of other function call, can saved handles
(in whichever location gets loaded file). suppose have map slider control coordinates number of frames have (though maybe have done this?).
Comments
Post a Comment