how to get data cursor values on user input ?

76 visualizaciones (últimos 30 días)
yogesh jain
yogesh jain el 9 de En. de 2016
Comentada: Adam Danz el 29 de Oct. de 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 comentario
Adam Danz
Adam Danz el 29 de Oct. de 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.

Iniciar sesión para comentar.

Respuestas (2)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Properties en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by