how to get data cursor values on user input ?

77 ビュー (過去 30 日間)
yogesh jain
yogesh jain 2016 年 1 月 9 日
コメント済み: Adam Danz 2020 年 10 月 29 日
Hello all , how can I get value of data cursor with using datacursormode and store into a variable without using pause command ? Means it should wait infinitely till when user gives input .Now I am using this code ...
h = datacursormode;
set(h,'DisplayStyle','datatip','SnapToData','off');
pause(5);
s = getCursorInfo(h);
x=s.Position;
Thank you
  1 件のコメント
Adam Danz
Adam Danz 2020 年 10 月 29 日
> "how can I get value of data cursor ... and store into a variable without using pause command"
There's no need for pause(5) in the first place. If you're having trouble with the timeing of the graphics updates you can reduce the pause to pause(0.1). Otherwise, your solution is sufficient to extract the data point coordinates.
If you want to extract all of the data tip text, you can use getDataTips() from the file exchange.

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

回答 (2 件)

Tara Prasad Mishra
Tara Prasad Mishra 2017 年 9 月 22 日
Hi,
You can do the following:-
set(gcf,'CurrentCharacter',char(1));
h=datacursormode;
set(h,'DisplayStyle','datatip','SnapToData','off');
waitfor(gcf,'CurrentCharacter',char(32));
s = getCursorInfo(h);
x=s.Position;
In the first line, you set the CurrentCharacter to the character of ASCII value 1. Next line turns on the data cursor mode and waits till the user presses the character of ASCII value 32 (spacebar). After the user presses spacebar getCursorInfo(h) collects the information of the cursor. It waits indefinitely till the user presses the spacebar.
Thanks.

Walter Roberson
Walter Roberson 2016 年 1 月 10 日
datacursormode is not about users giving input. datacursormode generates an UpdateFcn callback when the user moves the cursor, but cursor movement itself is not giving input (unless the user is drawing a curved line in freehand mode...)
If "gives input" has to do with the user clicking, then you should be using some other mechanism. For example there is ginput(), and there is using a figure WindowButtonMotionFcn . At any time you can request the CurrentPoint property of a figure or an axes.
  2 件のコメント
yogesh jain
yogesh jain 2016 年 1 月 10 日
But can we use 'ginput' for 3d volumes ?
Walter Roberson
Walter Roberson 2016 年 1 月 10 日
axes currentpoint along with axes ButtonDownFcn callback.

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

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by