我是靠谱客的博主 怕孤单小伙,最近开发中收集的这篇文章主要介绍matlab 判断鼠标按下_MATLAB如何获取鼠标点击坐标,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

I have made my GUI using GUIDE. I have an axes (tag=axes1). An image is displayed in the axes.

When i click on the image(inside axes) I need to get the coordinates.

I get the coordinate values when image is not added to axes.But image is displayed in axes do no obtain the axes. How to get the coordinates?

解决方案

Let's assume that you've plotted the image with handle imageHandle that:

imageHandle = imshow(imageObj);

You should assign the ButtonDownFcn to the image handle not the axes handle that:

set(imageHandle,'ButtonDownFcn',@ImageClickCallback);

and get the mouse coordinates from this function as follows:

function ImageClickCallback ( objectHandle , eventData )

axesHandle = get(objectHandle,'Parent');

coordinates = get(axesHandle,'CurrentPoint');

coordinates = coordinates(1,1:2);

%// then here you can use coordinates as you want ...

end

You can try this small demo to check my answer:

function demoOnImageClick

clc;clear;

imObj = rand(500,500);

figure;

hAxes = axes();

imageHandle = imshow(imObj);

set(imageHandle,'ButtonDownFcn',@ImageClickCallback);

function ImageClickCallback ( objectHandle , eventData )

axesHandle = get(objectHandle,'Parent');

coordinates = get(axesHandle,'CurrentPoint');

coordinates = coordinates(1,1:2);

message = sprintf('x: %.1f , y: %.1f',coordinates (1) ,coordinates (2));

helpdlg(message);

end

end

最后

以上就是怕孤单小伙为你收集整理的matlab 判断鼠标按下_MATLAB如何获取鼠标点击坐标的全部内容,希望文章能够帮你解决matlab 判断鼠标按下_MATLAB如何获取鼠标点击坐标所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(128)

评论列表共有 0 条评论

立即
投稿
返回
顶部