Effacer les filtres
Effacer les filtres

Passing handles to datatip user function in GUI

2 vues (au cours des 30 derniers jours)
Ali
Ali le 29 Mar 2013
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!

Réponse acceptée

Walter Roberson
Walter Roberson le 29 Mar 2013
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 commentaires
Walter Roberson
Walter Roberson le 30 Mar 2013
Odd, but it is documented. Okay, so looks like it should be
handles = guidata( ancestor(event_obj.Target, 'figure') );
Ali
Ali le 30 Mar 2013
Thanks, that was it!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by