Passing handles to datatip user function in GUI
조회 수: 6 (최근 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!
댓글 수: 0
채택된 답변
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
2013년 3월 30일
Odd, but it is documented. Okay, so looks like it should be
handles = guidata( ancestor(event_obj.Target, 'figure') );
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!