How to store a selected axes-point in handles

Hello fellow Matlab-Users,
This is what i want:
  • User selects a point in an axes_object.
  • My program stores selected point in my figure's handles_object.
My first approach was to use the datacursormode's UpdateFcn to extract the data. I couldn't find a solution to the problem, that i can't reach the handles_object from the UpdateFcn.
My second approach was to write my own datacursormode. The new problem is, that i can't catch the ButtonDownFcn_trigger of my axes_object. Now im not sure if that is because the axes_object is located inside a panel inside a figure. Or because "Some Plotting Functions Reset the ButtonDownFcn" as i read in the axes_properties_docu.
Now i really search for some advice how to get that *** Coordinates.
Best regards, Peter
This is the most useful help i found so far:

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 23 Sep. 2011

0 Stimmen

Within your UpdateFcn callback, if you named the first parameter as hObject, then
ancestor(hObject, 'figure')
gets you the handle of the object's figure.
If by handles_object you are referring to "handles" such as is commonly passed around in GUIDE created programs, then just use
handles = guidata(hObject);
guidata() knows enough to climb the parent chain of the object it is given to find the parent figure.

Weitere Antworten (1)

Peter
Peter am 26 Sep. 2011

0 Stimmen

Thx but i need more help.
%When i try:
function output_txt = myUpdateFcn(hObject, event_obj)
x = ancestor(hObject, 'figure')
%it returns x = []
I try to reask my question:
this is my code...
function datacursormode_Callback(hObject, eventdata, handles)
dcm_obj = datacursormode(gcf);
set(dcm_obj,'UpdateFcn',@myUpdateFcn);
funtion myUpdateFcn(obj, event_obj)
handles.selectedCoordinate = (get(event_obj, 'position'));
% This doesnt work cause myUpdateFcn doesnt know hObject
% And i dont know how to pass hObject to myUpdateFcn
guidata(hObject, handles);
Thx, Peter

5 Kommentare

Jan
Jan am 26 Sep. 2011
@Peter: In your case "obj" is the same variable as "hObject" in Walter's example. It is just another *name*. Can you see the similarities:
myUpdateFcn(hObject, event_obj)
myUpdateFcn(obj, event_obj)
Peter
Peter am 26 Sep. 2011
true.
but if i would write:
myUpdateFcn(Pi, event_obj)
Pi wouldnt be 3.14
as
myUpdateFcn(hObject, event_obj)
hObject isnt my figure
the value of the first parameter is actually empty
perhaps this is part of my problem
Walter Roberson
Walter Roberson am 26 Sep. 2011
handles = guidata(event_obj.Target);
Question: isn't datacursormode_Callback already the UpdateFcn ? Is there any reason to reset it to myUpdateFcn? Why not use it as-is and access the handles parameter that is already passed down?
Peter
Peter am 26 Sep. 2011
i don't have a datacursormode_Callback.
sorry, the name of the function was bad.
it's an ordinary button_Callback that executes datacursormode.
but i will try what u wrote and have 2 additional possible solutions to test:
- i didn't set(dcm_obj,'figure', hObject) yet
- and it seems to be possible to add aditional args with: set('UpdateFcn',{@myUpdateFcn,arg1,arg2})
i will test all that at wednesday and post if it helped.
Peter
Peter am 28 Sep. 2011
i used:
set(dcm_obj,'UpdateFcn',{@myUpdateFcn,arg1,arg2})
to pass the handles to myUpdateFcn.
and it worked!
BIG thx for the help

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by