在MATLAB中设置数据游标的精度

1、新建一个名称为NewCallback.m的M文件,代码如下:

function output_txt = myfunction(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');
output_txt = {['X: ',num2str(pos(1),5)],...
% 此处的pos(1)后的数字,即X轴的数据游标的显示精度位数
['Y: ',num2str(pos(2),5)]};
% 此处的pos(2)后的数字,即Y轴的数据游标的显示精度位数

% 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),5)];
% 此处的pos(3)后的数字,即Z轴的数据游标的显示精度位数
end

2、将该文件保存在MATLAB的当前文件夹目录下
3、输入画图代码,并在figure下输入以下代码:

dcm_obj = datacursormode(gcf);
set(dcm_obj,'UpdateFcn',@NewCallback)
  • 5
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值