Set programmatically a Data Cursor in an Axes represenation in a GUI
14 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Prashant Arora
2017-10-17
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
2017-11-15
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!