0

I'm writing a matlab program and I'm trying to pass around my handles struct to ALL my callbacks. The only problem is that I'm using GUIDE and I can't pass in handles as an argument to a function I created:

%The proper slider callback: Deleted the default within GUIDE

function sliderContValCallback(hFigure,eventdata)

%test it out- get the handles object and dispay the current value
%getappdata(handles.video_loader_button,'handles');

handles = guidata(hFigure);

handles.currentFrame = floor(get(handles.slider,'Value'));
set(handles.frameBox,'String',num2str(handles.currentFrame));
fprintf('slider value: %f\n',get(handles.slider,'Value'));


updateAxes(handles);

The problem is that the way I'm 'getting' handles right now is that it isn't really the same handles that the rest of the UI object callback functions are using. I also thought of passing handles around with getappdata, but you need handles to even do that so I'm stuck. This has been causing some problems, any help as to how to get around this would be awesome, thanks!

EDIT: I deleted the call back generated by GUIDE, so that I could use sliderContValCallback as a function handle and call it here:

handles.sliderListener = addlistener(handles.slider,'ContinuousValueChange',...
    @(hFigure,eventdata) sliderContValCallback(hObject,eventdata));

for continuous updates as the user drags the slider(This is used to scroll through a video, and its working well).

The real reason I'm questioning this is because when I call:

allCoords  = getappdata(handles.axes1,'mydata');
coordsXYZ = allCoords.clickcoordinates; %Do this to access the field     'allCoords' within 'mydata'
curIndex = allCoords.currentIndex;

if numel(coordsXYZ)>0
    for i = 1:length(coordsXYZ)
        coordXY = [coordsXYZ(i).x,coordsXYZ(i).y];
        %viscircles(handles.axes1,coordXY,1,'EdgeColor','r');
        hold on;
        plot(coordsXYZ(i).x,coordsXYZ(i).y,'o');
    end
end

everything works but a figure is generated for some reason, the plot is drawn to an image on handles.axes1. It's weird because this random figure pops up ONLY when I update the slider by moving it.

sam
  • 17
  • 7
  • why did you delete the default callback generated by GUIDE? Also what does `handles` contain after this command: `guidata(hFigure)`? – Benoit_11 Aug 12 '15 at 17:00
  • Hey @Benoit_11 I just edited the post, and I think `guidata(hFigure)` returns something fairly similar to normal handles. – sam Aug 12 '15 at 17:15
  • The last line of your edit is important: the figure pops up when you release the slider? Or as you continuously move it? – Benoit_11 Aug 12 '15 at 17:22
  • As I move it, and it redraws onto the same figure. Like there aren't 1000 figures, but one that continually updates? – sam Aug 12 '15 at 17:26
  • mhh weird. What if you add `'Parent',handles.axes1` as an extra parameter to `plot`. Also, the slider callback generated by GUIDE is the one executed when you use arrows to move it or when you stop dragging it; that's different than the callback you associate with the listener object. So in fact you don't necessarily need to delete it if you use a listener. That's why I was wondering when did the figure popped up. – Benoit_11 Aug 12 '15 at 17:29
  • With `'Parent'` I got _Invalid first data argument._, with just `handles.axes1` I got the same weird problem of a pop up figure. If I use `viscircles(handles.axes1,coordXY,1,'EdgeColor','r');` instead the same thing happens, except if I use it without the `handles.axes1` parameter it actually draws the circles to the pop up figure rather than the image on the axes1. – sam Aug 12 '15 at 17:35
  • Oh shoot I mixed up `plot` with `imshow`; with `plot` we specify the axes as a 1st argument and the `'parent',...` thing is for imshow sorry about that. – Benoit_11 Aug 12 '15 at 17:39
  • yeah I'm a bit puzzled I must say. I'll look into it later today. – Benoit_11 Aug 12 '15 at 17:42

0 Answers0