Passing handles to datatip user function in GUI

7 ビュー (過去 30 日間)
Ali
Ali 2013 年 3 月 29 日
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') );
Ali
Ali 2013 年 3 月 30 日
Thanks, that was it!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by