Set programmatically a Data Cursor in an Axes represenation in a GUI
조회 수: 15 (최근 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!