您的位置:首页 > 编程语言 > MATLAB

matlab之作图设置游标的精度

2017-12-21 11:23 2276 查看
matlab画出的figure游标的精度往往是固定的,这就对我们的调试和查看数据造成了不便。

那么怎么修改游标的精度呢?

首先,获取游标

dcm_obj = datacursormode(gcf);


然后对游标的精度进行设置:

set(dcm_obj,'UpdateFcn',@NewCallback)


这个NewCallback是什么东西呢?这是一个可以返回游标精度的函数,具体内容如下:

function output_txt = NewCallback(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),6)],...
['Y: ',num2str(pos(2),6)]};

% 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


pos(1),6就是指6位有效数字。自己可以试着修改一下,看看效果。

注意,NewCallback文件一定要和画图文件在统一目录下,或者将其加入matlab的路径变量。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: