我正在制作一个self函数来更改光标在GUI图形中显示的文本。这就是我当时所做的:
dcm=datacursormode(hAxes.figure);
datacursormode on
set(dcm,'update',@myfunction)
function output_txt = runnumber(obj,event_obj)
% Display the position of the data cursor
% obj Currently not used (empty)
% event_obj Handle to event object
% output_txt Data cursor text string (string or cell array of strings).
pos = get(event_obj,'Position');
%getCursorInfo(dcm)
%inputDrDataCell
% Get the handle to the data cursor.
menu = findall(get(gcf,'Children'),'Type','uicontextmenu');
menuCallback = get(menu,'Callback');
dataCursor = menuCallback{2};
% Get the coordinates if a datatip exists.
info = getCursorInfo(dataCursor);
if ~isempty(info)
number = info.DataIndex
end
output_txt = {['X: ',num2str(pos(1),4)],...
['Y: ',num2str(pos(2),4)],...
['Run number:',num2str(number)]};
% If there is a Z-coordinate in the position, display it as well
%if length(pos) > 2
% output_txt{end+1} = ['Z: ',num2str(pos(3),4)];
%end
end但是,我想向@myfunction传递更多的输入参数,以便显示轴的名称、原始数据文件等。
发布于 2013-07-02 19:41:54
通过使用函数句柄和单元格中的附加参数将附加参数提供给回调:
set(dcm,'update',{@myfunction,arg3,arg4});它们对应于函数的第三个和第四个输入:
function output_txt = runnumber(obj,event_obj,arg3,arg4)发布于 2013-07-02 22:05:50
另一种方法,Hugh Nolan的答案没有错,是使用匿名函数句柄,如下所示:
set(dcm, 'update', @(obj,event) runnumber(obj,event,arg3,arg4));哈!
https://stackoverflow.com/questions/17424499
复制相似问题