Can Matlab determine cursor position continuously?

I have an image plot that was created with "imagesc", and I can use ginput to select (x,y) points on the image, then I can read the value of that particular pixel which I output to a figure that accompanies the image.
What I would like to do is have the (x,y) point and pixel value output continuously as I "mouse over" the image, without clicking. Can this be done?

 採用された回答

Jan
Jan 2011 年 7 月 13 日

1 投票

The WindowButtonMotionFcn can help:
FigH = figure('WindowButtonMotionFcn', @MotionFcn)
function MotionFcn(FigH, EventData)
get(FigH, 'CurrentPoint')
get(get(FigH, 'CurrentAxes'), 'CurrentPoint')
Now the current point is written to the command window, if the mouse if moved over the figure.

5 件のコメント

Art
Art 2011 年 7 月 13 日
So if I have a figure already created, how would I use this instead of a new figure? Would I have to create this figure from the beginning with this function?
Jan
Jan 2011 年 7 月 13 日
@Art: You can modify the properties of an existing figure also: set(FigureHandle, 'WindowButtonMotionFcn', @MotionFcn).
Walter Roberson
Walter Roberson 2011 年 7 月 13 日
Be sure to read about the limitations of CurrentPoint in the Figure Properties page, http://www.mathworks.com/help/techdoc/ref/figure_props.html
Art
Art 2011 年 7 月 14 日
Thanks, Jan, that worked perfectly for what I wanted to do.
Jim Hokanson
Jim Hokanson 2017 年 10 月 24 日

サインインしてコメントする。

その他の回答 (2 件)

Sean de Wolski
Sean de Wolski 2011 年 7 月 13 日

0 投票

See Matt Tearle's doodle function in this thread:
Walter Roberson
Walter Roberson 2011 年 7 月 13 日

0 投票

No, it is not possible to have the cursor position updated continuously. PS/2 and USB mice and serial mice only send coordinate updates periodically, not continuously. (Old joysticks, on the other hand, used to have analog position signals; with those and an analog to digital convertor, you could update the position as fast as the convertor could run.)

2 件のコメント

Jan
Jan 2011 年 7 月 13 日
@Walter: I think the frequency of updates of the pixel position is limited by the runtime of the Matlab function for evaluating. For a fast movement the mouse position will not be displayed for all pixels.
Anyhow, I assume that "without clicking" is more important for the OP than a real continuity.
Walter Roberson
Walter Roberson 2011 年 7 月 13 日
Mice do not report for every pixel! USB mice, by default, poll at a maximum of 125 Hz; see http://www.nextlevelgamer.com/tweaks/optimizing-your-usb-mouse-polling-rate
I have seen reports that PS/2 mice max out at 125 Hz but are often appreciably slower.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeData Exploration についてさらに検索

質問済み:

Art
2011 年 7 月 13 日

コメント済み:

2017 年 10 月 24 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by