Set programmatically a Data Cursor in an Axes represenation in a GUI

21 vues (au cours des 30 derniers jours)
Ismael Vivó
Ismael Vivó le 13 Oct 2017
Commenté : Sanders A. le 12 Avr 2022
I am working on a GUI with matlab 2017b. In this GUI I have some axes representations (handles.axes). I would like to know how to set programmatically a group of data cursors that I have stored using the getCursorInfo() function.
In oder words, I have obtained and stored the position of a group of Data Cursors using the getCursorInfo() function and I want to set them in another plot. Anyone knows how to do this?
Thank you!

Réponses (2)

Prashant Arora
Prashant Arora le 17 Oct 2017
Hi Ismael,
You can use the following method to create a data tip in another figure and set it's position from the getCursorInfo data.
hFigure = figure;
hLine = plot(1:10);
input('Create Data Tip and Press Enter');
dcmObj1 = datacursormode(hFigure);
curInfo = getCursorInfo(dcmObj1);
hFigure2 = figure;
hLine2 = plot(1:10);
dcmObj2 = datacursormode(hFigure2);
dTip = createDatatip(dcmObj2,hLine2);
dTip.Position = [curInfo.Position 0];
After the first figure opens up, create a data tip and press Enter in the MATLAB command window. The code should create a new figure and set it's position correctly. You might need to map the target of the cursorInfo to find the correct target for the createDatatip function. In this case, I already knew to create the data tip on the line.
Hope this helps!
Best,
Prashant

Yair Altman
Yair Altman le 15 Nov 2017
As followup to Prashant's answer, additional information on the undocumented/unsupported datacursormode object's createDatatip function and related functionality can be found in https://undocumentedmatlab.com/blog/controlling-plot-data-tips
Note that this functionality is undocumented/unsupported, but is surprisingly still very well relevant today as it was back in 2011 when I wrote that article.
Just for the record, the official documentation of the datacursormode function says explicitly that:
"You place data tips only by clicking data objects on graphs. You cannot place them programmatically (by executing code to position a data cursor)."
This is in fact WRONG AND MISLEADING, as I explained in the article above. Hopefully, MathWorks will fix the official documentation accordingly.
  1 commentaire
Tommaso
Tommaso le 26 Mar 2018
Hello,
is it possible to have data cursor or similar for UIfigure?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by