how to get data cursor values on user input ?

79 views (last 30 days)
yogesh jain
yogesh jain on 9 Jan 2016
Commented: Adam Danz on 29 Oct 2020
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 Comment
Adam Danz
Adam Danz on 29 Oct 2020
> "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.

Sign in to comment.

Answers (2)

Tara Prasad Mishra
Tara Prasad Mishra on 22 Sep 2017
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 on 10 Jan 2016
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.

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!