我正在创建一个自我功能来改变我的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,以显示轴的名称,原始数据文件等。 有什么帮助吗?
答案 0 :(得分:2)
通过使用函数句柄和单元格中的其他参数,为回调提供了其他参数:
set(dcm,'update',{@myfunction,arg3,arg4});
这些对应于函数的第三个和第四个输入:
function output_txt = runnumber(obj,event_obj,arg3,arg4)
答案 1 :(得分:1)
另一种方法,Hugh Nolan的答案没有错,就是使用匿名函数句柄:
set(dcm, 'update', @(obj,event) runnumber(obj,event,arg3,arg4));
HTH!