how to get data cursor values on user input ?

79 visualizzazioni (ultimi 30 giorni)
yogesh jain
yogesh jain il 9 Gen 2016
Commentato: Adam Danz il 29 Ott 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 Commento
Adam Danz
Adam Danz il 29 Ott 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.

Accedi per commentare.

Risposte (2)

Tara Prasad Mishra
Tara Prasad Mishra il 22 Set 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 il 10 Gen 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 Commenti
yogesh jain
yogesh jain il 10 Gen 2016
But can we use 'ginput' for 3d volumes ?
Walter Roberson
Walter Roberson il 10 Gen 2016
axes currentpoint along with axes ButtonDownFcn callback.

Accedi per commentare.

Categorie

Scopri di più su Graphics Object Properties in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by