在Matlab中打开数据光标模式时,如何获取单击点的坐标? [英] How to get coordinates of the clicked point when data cursor mode is on in matlab?

查看:245
本文介绍了在Matlab中打开数据光标模式时,如何获取单击点的坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用Matlab设计和编程GUI,对此我并不熟悉.

I'm trying to design and program a GUI in Matlab, with which I'm not familiar.

基本上,我有两个组件,分别是轴"和列表框".轴上有一个RGB图像.我打算将所选点添加到列表框中.

Basically, I have two components, which are "axes" and "list box". There is an RGB image in the axes. I'm planning to add the selected point to the list box.

以下代码可以正常工作,但是我想在数据游标打开时使其工作.

The following code works just fine, but I would like to make it work when the data cursor is on.

当数据光标打开时如何使它工作?

How can I make it work when the data cursor is on?

% 100x100x3 RGB image
RgbImage = randi(100, 100, 100, 3);

% Draw the image
axesHandle = axes();
imageHande = imagesc(RgbImage);
axis image;

% ButtonDownFc
set(imageHandle, 'ButtonDownFcn', @imageButtonDownFcn);
function imageButtonDownFcn(hObject, eventdata)
    p = get(gca, 'CurrentPoint');
    x = floor( p(1) );
    y = floor( p(2) );

    % Some code to add the [x y] to the list box
end

问题在于打开数据游标时未触发功能 imageButtonDownFcn .

Edit 1: The problem is that the function imageButtonDownFcn is not triggered when data cursor is on.

推荐答案

对于您的代码中剩余的部分,请尝试使用此方法.在您的情况下,请记住将"listbox1"编辑为用于listbox的标签-

Try this for the part that is remaining in your code. Remember to edit "listbox1" to the tag used for listbox in your case -

contents = cellstr(get(handles.listbox1,'String'));
str1 = [ '[' num2str(x) ' ' num2str(y)  ']' ];
contents(size(contents,1)+1,1) = {str1};
set(handles.listbox1,'String',contents);

让我们知道它是否有效!

Let us know if it works!

这篇关于在Matlab中打开数据光标模式时,如何获取单击点的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆