Set programmatically a Data Cursor in an Axes represenation in a GUI
14 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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!
0 Commenti
Risposte (2)
Prashant Arora
il 17 Ott 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
il 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 Commento
Vedere anche
Categorie
Scopri di più su Specifying Target for Graphics Output 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!