Passing handles to datatip user function in GUI

2 次查看(过去 30 天)
Hello,
I'd like to pass data to a user defined fucntion that is run every time that the data tip is used in order that I can display further information about the data on the graph interactively.
The code in the main GUI looks like:
cursorMode = datacursormode(gcf);
set(handles.cursorMode, 'enable','on', 'UpdateFcn', @setDataTipTxtFFT)
This calls:
function output_txt = setDataTipTxtFFT(obj,event_obj)
pos = get(event_obj,'Position');
line_id = get(event_obj,'Target')
Freq = pos(1)
Amp = pos(2)
s1 = sprintf('freq = %1.4g Telsa', Freq);% = %1.4g T', Freq);
s2 = sprintf('amp = %1.4g', Amp);% = %1.4g bar', Amp);
%s3 = sprintf('amp = %1.4g', P);% = %1.4g bar', Amp);
output_txt = {s1; s2; s3};
-----------------------------------------------------------
What I would like to do is cross reference the index of the various plots with the index of the loaded files which are stored in the main gui's handle structure.
I don't seem to be able to just call the handles.LoadedFileIndex or such like inside the function @setDataTipTxtFFT
I tried passing handles in the variable list of @setDataTipTxtFFT
Should this work, and if not, could you suggest what the most eficient way of doing this might be. I though the handles structure was meant to get around the defining of global variables, which I could access with setappdata and getappdata
Iss this one of those instances where using this method is unavoidable?
Thanks!

采纳的回答

Walter Roberson
Walter Roberson 2013-3-29
After the "function" line, add
handles = guidata( ancestor(obj, 'Figure') );
Note: this will not work if the figure with the plot whose datatips you are using is not the same as your figure GUI. If that is the case, indicate that and I will show the more complicated approach.
  5 个评论
Walter Roberson
Walter Roberson 2013-3-30
Odd, but it is documented. Okay, so looks like it should be
handles = guidata( ancestor(event_obj.Target, 'figure') );

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by