From: Corey Kelly on
"Corey Kelly" <ckelly01(a)uoguelph.ca> wrote in message <htjodd$6fa$1(a)fred.mathworks.com>...
> "Corey Kelly" <ckelly01(a)uoguelph.ca> wrote in message <htjg34$mqe$1(a)fred.mathworks.com>...
> > "us " <us(a)neurol.unizh.ch> wrote in message <htjdo4$fpu$1(a)fred.mathworks.com>...
> > > "Corey Kelly"
> > > > handles.currimage = imshow(handles.imagestack(:,:,1),[0 1012]);
> > > > set(handles.currimage, 'ButtonDownFcn',@axes1_ButtonDownFcn);
> > > >
> > > > Now I can load the image and get a response when I click on it. Unfortunately, the response in the following error:
> > > >
> > > > ??? Input argument "handles" is undefined.
> > > >
> > > > Error in ==> min_analysis>axes1_ButtonDownFcn at 185
> > > > cp = get(handles.axes1,'CurrentPoint');
> > > >
> > > > ??? Error while evaluating image ButtonDownFcn
> > >
> > > yes, of course...
> > > carefully follow the syntax required to build callback functions...
> > >
> > > us
> >
> > Thank you so much! Played around a bit, ended up with
> >
> > set(handles.currimage, 'ButtonDownFcn',{@axes1_ButtonDownFcn,handles});
> >
> > and now it works! I click, it gives coordinates. Now my issue is figuring out what the coordinates mean.. haha...
> > Coordinates from the axes object were much more straightforward. Now I'm getting huge negative numbers.
>
> So it seems my problem is not solved. This method for setting the ButtonDownFcn for the image object doesn't seem to pass the handles correctly to the callback. I can't reference any of my program variables properly from within the callback. Is my syntax correct?
>
> set(handles.currimage, 'ButtonDownFcn',{@axes1_ButtonDownFcn,handles});
>
> I tried changing it to
>
> set(handles.currimage, 'ButtonDownFcn',{@axes1_ButtonDownFcn,hObject, eventdata, handles});
>
> but then I get the following error:
>
> ??? Error using ==> min_analysis>axes1_ButtonDownFcn
> Too many input arguments.
>
> ??? Error while evaluating image ButtonDownFcn
>
> I'm confused about this "@" notation and how exactly this function is being passed.

Double post, sorry. I'll take a look through that. Thanks us
From: Walter Roberson on
Corey Kelly wrote:

> set(handles.currimage, 'ButtonDownFcn',{@axes1_ButtonDownFcn,hObject,
> eventdata, handles});
>
> but then I get the following error:
>
> ??? Error using ==> min_analysis>axes1_ButtonDownFcn
> Too many input arguments.
>
> ??? Error while evaluating image ButtonDownFcn
>
> I'm confused about this "@" notation and how exactly this function is
> being passed.

Do not pass hObject and eventdata explicitly in your callback. If you were to
try doing so, you would at best be passing down their current value as of the
time the callback was set. Matlab takes the callback you give and when
automatically inserts the source and event as the first and second parameters
before any parameters you define. e.g.,

{@fun, A1, A2}

will be called as fun(src, event, A1, A2)

It is equivalent of

callback = get(Object, 'Callback');
callback{1}(src, event, callback{2:end});
From: Corey Kelly on
*snip*
> a hint:
> - did you follow these guidelines...
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/f1-5978.html
>
> us


I've re-written my callback following those guidelines:

set(handles.currimage, 'ButtonDownFcn',@(src,eventdata)axes1_ButtonDownFcn(src,eventdata,handles));

and while I'm not getting any errors, I think there's still an issue with handles being passed properly to the callback. Specifically, my problem is this. I want to grab the image coordinates, and append them to an array which is stored at handles.coords
I've tried to do this as follows:

function axes1_ButtonDownFcn(hObject, eventdata, handles)
cp = get(handles.axes1,'CurrentPoint');
handles.coords = [handles.coords; round(cp(1,1)) round(cp(1,2))];
guidata(hObject, handles);

But for some reason, handles.coords only ever contains the most recent set of coordinates. It seems like the variable isn't being permanantly updated.
From: Walter Roberson on
Corey Kelly wrote:

> I've re-written my callback following those guidelines:
>
> set(handles.currimage,
> 'ButtonDownFcn',@(src,eventdata)axes1_ButtonDownFcn(src,eventdata,handles));
>
>
> and while I'm not getting any errors, I think there's still an issue
> with handles being passed properly to the callback.

Yes, that would pass down the value of handles as of the time that the
callback was defined. As handles is a structure, that is not what you want.

As you will not be changing the figure number (I gather), pass down the figure
number and in the callback

handles = guidata(FigureNumber)
From: Steven Lord on

"Walter Roberson" <roberson(a)hushmail.com> wrote in message
news:htju1a$fr9$2(a)canopus.cc.umanitoba.ca...
> Corey Kelly wrote:
>
>> I've re-written my callback following those guidelines:
>>
>> set(handles.currimage,
>> 'ButtonDownFcn',@(src,eventdata)axes1_ButtonDownFcn(src,eventdata,handles));
>> and while I'm not getting any errors, I think there's still an issue with
>> handles being passed properly to the callback.
>
> Yes, that would pass down the value of handles as of the time that the
> callback was defined. As handles is a structure, that is not what you
> want.
>
> As you will not be changing the figure number (I gather), pass down the
> figure number and in the callback
>
> handles = guidata(FigureNumber)

Actually, GUIDATA can accept any figure descendant as its input; since no
Handle Graphics object can be parented to more than one figure at the same
time, this unambiguously specifies the figure from which you want to
retrieve the data. Since you're already passing the handle to a figure
descendant (src) into the ButtonDownFcn, there's no need to add an extra one
to the argument list, and this simplifies the SET call (as long as
axes1_ButtonDownFcn accepts the standard two inputs.)

set(handles.currimage, 'ButtonDownFcn',@axes1_ButtonDownFcn);

--
Steve Lord
slord(a)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


First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9 10 11
Prev: mbuild -setup doesn't see my compiler
Next: Using imcontrast