首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@functions中的参数

@functions中的参数
EN

Stack Overflow用户
提问于 2013-07-02 19:33:08
回答 2查看 252关注 0票数 1

我正在制作一个self函数来更改光标在GUI图形中显示的文本。这就是我当时所做的:

代码语言:javascript
复制
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传递更多的输入参数,以便显示轴的名称、原始数据文件等。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-07-02 19:41:54

通过使用函数句柄和单元格中的附加参数将附加参数提供给回调:

代码语言:javascript
复制
set(dcm,'update',{@myfunction,arg3,arg4});

它们对应于函数的第三个和第四个输入:

代码语言:javascript
复制
function output_txt = runnumber(obj,event_obj,arg3,arg4)
票数 2
EN

Stack Overflow用户

发布于 2013-07-02 22:05:50

另一种方法,Hugh Nolan的答案没有错,是使用匿名函数句柄,如下所示:

代码语言:javascript
复制
set(dcm, 'update', @(obj,event) runnumber(obj,event,arg3,arg4));

哈!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17424499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档