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)

猜你喜欢

转载自blog.csdn.net/qq_37407054/article/details/108873877
今日推荐