handles not updated using guidata

  • Follow


Hello,

I have an image displayed via imshow from the image processing toolbox. Since my image is in front of the axes1 I'm not able to use the 'ButtonDownFcn' of my axes. Hence, I define a 'ButtonDownFcn' for my image in the 'OpeningFcn' of my figure:

axH = handles.axes1;
image = imread([pathname,filename]);
imshow(image,'Parent',axH);
handles.image = get(axH,'Children');
set(handles.image,'ButtonDownFcn',{@axes1_ButtonDownFcn,handles});
% Update handles structure
guidata(hObject, handles);

In the 'axes1_ButtonDownFcn' of the image, I try to add some additional handles to the handles structure and save it back to handles:

handles.marker1 = marker;
guidata(hObject, handles);

In the next call of my  'axes1_ButtonDownFcn', the previously added handle is not included in handles, why?

Does anybody know why the handles structure is not updated???
0
Reply Johannes 9/7/2010 1:02:25 PM


"Johannes " <J.Ruhhammer@gmx.de> wrote in message 
news:i65d51$qku$1@fred.mathworks.com...
> Hello,
>
> I have an image displayed via imshow from the image processing toolbox. 
> Since my image is in front of the axes1 I'm not able to use the 
> 'ButtonDownFcn' of my axes.

Set the HitTest property of your image to 'off'.

> Hence, I define a 'ButtonDownFcn' for my image in the 'OpeningFcn' of my 
> figure:
>
> axH = handles.axes1;
> image = imread([pathname,filename]);
> imshow(image,'Parent',axH);
> handles.image = get(axH,'Children');
> set(handles.image,'ButtonDownFcn',{@axes1_ButtonDownFcn,handles});

This sets the ButtonDownFcn to contain a cell array, the first element of 
which is a function handle and the second is a copy of the handles structure 
_at the time this SET call executes_.  Note that this COPY does NOT update 
as the master copy does; it's fixed until or unless you modify the 
ButtonDownFcn for the image.

> % Update handles structure
> guidata(hObject, handles);
>
> In the 'axes1_ButtonDownFcn' of the image, I try to add some additional 
> handles to the handles structure and save it back to handles:
>
> handles.marker1 = marker;
> guidata(hObject, handles);
>
> In the next call of my  'axes1_ButtonDownFcn', the previously added handle 
> is not included in handles, why?

See above.  If changing the HitTest property is not sufficient, use GUIDATA 
inside the callback with the first input argument (the handle of the object 
whose callback is executing) as the input to create a copy of the "master" 
handles structure in the callback workspace, modify that copy, and call 
GUIDATA again to update the master copy.

-- 
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on 
http://www.mathworks.com 

0
Reply slord (13279) 9/7/2010 1:08:28 PM


"Steven_Lord" <slord@mathworks.com> wrote in message 
> >
> > I have an image displayed via imshow from the image processing toolbox. 
> > Since my image is in front of the axes1 I'm not able to use the 
> > 'ButtonDownFcn' of my axes.
> 
> Set the HitTest property of your image to 'off'.

Hi Steven, 
thanks for your fast reply. I tried to set the HitTest property to 'off' but it didn't work. My underlying axes still doesn't recognize a button click (when I remove the image, everything works fine). Do you know why?

The other thing worked perfectly:

.... ButtonDownFcn...
handles = guidata(hObject)
....
....
 guidata(hObject, handles);

Thanks for that!
0
Reply Johannes 9/7/2010 1:30:28 PM

2 Replies
304 Views

(page loaded in 0.028 seconds)

Similiar Articles:













7/25/2012 4:04:55 AM


Reply: