matlab定位坐标转换,Matlab:将全局坐标转换为图形坐标

以下是如何进行此转换的示例…

假设你有一个数字,那个数字包含一个带有句柄hAxes的轴对象.使用功能ginput可以选择轴内的点.要从get(0,’PointerLocation’)获得一组等效的点,它提供与屏幕相关的坐标,您必须考虑图形位置,轴位置,轴宽度/高度和轴限制.

这样做很棘手,因为您希望以相同的单位进行位置测量.如果要以像素为单位计算所有内容,这意味着您必须将对象的“单位”属性设置为“像素”,获取位置,然后将“单位”属性设置回原先的位置.我通常使用自己的函数get_in_units来完成这一部分:

function value = get_in_units(hObject, propName, unitType)

oldUnits = get(hObject, 'Units'); % Get the current units for hObject

set(hObject, 'Units', unitType); % Set the units to unitType

value = get(hObject, propName); % Get the propName property of hObject

set(hObject, 'Units', oldUnits); % Restore the previous units

end

使用上面的函数,你可以创建另一个函数get_coords来获取屏幕坐标并将它们转换为轴坐标:

function coords = get_coords(hAxes)

% Get the screen coordinates:

coords = get_in_units(0, 'PointerLocation', 'pixels');

% Get the figure posi

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值