matlab数据游标不能使用,matlab - MATLAB:永久设置图中的数据游标的“文本更新功能” - 堆栈内存溢出...

Thewaywewalk给出的永久性答案在R2015a中可能不再有效,可能在以后的版本中也不再有效。 所以在这里我分享临时解决方案和永久解决方案的解决方案

临时解决方案(单个图):

以下函数包含更新函数作为嵌套函数。 调用datacursorextra将其应用于当前图形,或datacursorextra(fig)将其应用于某个图形fig 。

function datacursorextra(fig)

% Use current figure as default

if nargin<1

fig = gcf;

end

% Get the figure's datacursormode, and set the update function

h = datacursormode(fig);

set(h,'UpdateFcn',@myupdatefcn)

% The actual update function

function txt = myupdatefcn(~,event)

% Short-hand to write X, Y and if available Z, with 10 digit precision:

lbl = 'XYZ';

txt = arrayfun(@(s,g)sprintf('%s: %.10g',s,g), lbl(1:length(event.Position)), event.Position,'uniformoutput',false);

% If a DataIndex is available, show that also:

info = getCursorInfo(h);

if isfield(info,'DataIndex')

txt{end+1} = sprintf('Index: %d', info.DataIndex);

end

end

end

永久解决方案(默认情况下适用于所有数据):

我还没有找到为数据游标设置默认UpdateFcn的方法,但是可以添加一些每次创建新图形时都会调用的代码。 startup.m下行添加到您的startup.m :

set(0,'defaultFigureCreateFcn',@(s,e)datacursorextra(s))

并确保上面给出的datacursorextra函数在您的Matlab路径中可用。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值