how to get data cursor values on user input ?

75 Ansichten (letzte 30 Tage)
yogesh jain
yogesh jain am 9 Jan. 2016
Kommentiert: Adam Danz am 29 Okt. 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 Kommentar
Adam Danz
Adam Danz am 29 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Tara Prasad Mishra
Tara Prasad Mishra am 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 am 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.
  2 Kommentare
yogesh jain
yogesh jain am 10 Jan. 2016
But can we use 'ginput' for 3d volumes ?
Walter Roberson
Walter Roberson am 10 Jan. 2016
axes currentpoint along with axes ButtonDownFcn callback.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by