matlab 鼠标 坐标,matlab动态标注及定位鼠标坐标代码

41528d3028836879cd698677c3999917.gifmatlab动态标注及定位鼠标坐标代码

程序说明:本程序可以实现扑捉画面上鼠标的坐标,可以进行动态标注。function dynpoint(arg,h) % Show the coordinates of a plot dynamically % % To start use: % dynpoint(h) % where h is a handle to a figure, axes or e.g. line. % % To delete use: % dynpoint( delete ,h) % where h is a handle to a figure, axes or e.g. line. % (you may also use: dynpoint delete) % % There can only be one dynamic plotter in a figure at a time. % % Example: % subplot(211), hline = plot(sin(1:10)) % subplot(212), plot(sin(1:100)) % dynpoint(hline) % 2010,11.30if ~exist( arg , var ) %判断输入变量的个数arg = gcf; end if ~isstr(arg) handle = arg; arg = init ; end switch arg case init if ~ishandle(handle) error( h is not a handle ) end [h,ax] = h2hax(handle); % delete old dynamic text object ht = findobj(h, tag ,[mfilename _text ]); if any(ht) delete(ht) end % text window at the bottom left corner % text in centred uicontrol(h,. style , text ,. pos ,[10 10 150 30],. fontsize ,20,. tag ,[mfilename _text ],. userdata ,ax(1)) % do the dynamic thing. set(h, windowbuttonmotionfcn ,[mfilename move ]) case move ht = findobj(gcbf, tag ,[mfilename _text ]); ax = overobj( axes ); if ~any(ax) ax = get(ht, userdata ); end p = get(ax, currentpoint ); p(1); %x 坐标值P(3); %y 坐标值set(ht, string ,sprintf( (%s) , 标注内容 ));case delete if ~exist( h , var ) h = gcf; end [h,ax] = h2hax(h); set(h, windowbuttonmotionfcn , ) ht = findobj(h, tag ,[mfilename _text ]); delete(ht) end% ---------- function [h,ax]=h2hax(handle) typ = get(handle, type ); if strcmp(typ, figure ) h = handle; ax = findobj(h, type , axes ); elseif strcmp(typ, axes ) h = get(handle, parent ); ax = handle; elseif strcmp( get(get(handle, parent ), type ), axes ) ax = get(handle, parent ); h = get(ax, parent ); End

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值