在matlab app designer 中, 设计UIAxes模块后,想通过点击图像中任意位置,获取鼠标指针的图像坐标信息和灰度值(如图1所示),在UIAxes 的callback 中写入如下代码时(如图2所示),运行时发现并不能实现想要的功能。
图1 UIAxes句柄模块,想通过鼠标点击图像任意位置获取坐标和灰度
图2 UIAxes 的callback 函数按照上述代码敲入
解决办法:
经过查阅,在国外找到一篇文章,阐述了原理和解决方案,直接放回复原文:
The UIAxesButtonDownFcn is triggered when clicking directly on the UIAxes itself.
Since the Image is a child object of the UIAxes, clicking on it does NOT trigger the UIAxesButtonDownFcn, but rather triggers the Image's own ButtonDownFcn.