How can I select multiple points using the Data Cursor and export the coordinates to the MATLAB workspace?

조회 수: 38 (최근 30일)
I would like to select multiple points in my figure using the Data Cursor, and export the coordinates of these points to the MATLAB workspace.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2021년 3월 9일
편집: MathWorks Support Team 2021년 3월 9일
The following example illustrates how you can create a structure array which contains the coordinates of manually selected data points in a 2-D plot.
1. Execute the following at the command prompt:
plot(1:100)
2. Click the Data Cursor button on the toolbar of the generated figure.
3. Click any point of your choice on the line in the figure.
4. While pressing the Alt key, repeat step 3 as many times as you like until you have selected your desired set of points.
5. Right-click (or control-click if you are on a Mac) anywhere on the figure, and select the 'Export Cursor Data to Workspace...' option from the context menu.
6. Accept the default variable name, "cursor_info", and click "OK".
7. Type "cursor_info.Position" at the MATLAB command prompt and hit "Enter".
The structure array "cursor_info" contains all information regarding selection sequence, x- and y-coordinates of the points selected. Note that for 3-D figures, the selection sequence value is replaced by the z-coordinate value for the points selected.
Also note that the "cursor_info" varable will not appear in the Workspace browser until you complete step 7 above.
It is possible to obtain the data cursor information in the MATLAB workspace programmatically. The following example and the documentation link illustrates how to use the datacursormode function to obtain data cursor information programmatically:
fig = figure;
z = peaks;
plot(z(:,30:35))
dcm_obj = datacursormode(fig);
set(dcm_obj,'DisplayStyle','datatip',...
'SnapToDataVertex','off','Enable','on')
Now, click on the line to place datatip before executing the next line of code.
c_info = getCursorInfo(dcm_obj)
  댓글 수: 2
Abhishek Pandey
Abhishek Pandey 2016년 6월 7일
편집: MathWorks Support Team 2023년 1월 13일
Hi Naman and Nida,
If you are still facing any issues with this, I would suggest you to contact MathWorks Technical Support.
- Abhishek
Adam Danz
Adam Danz 2020년 10월 29일
@Surabhi Verma, you can use getDataTips() from the file exchange to extract the data tip text and handles from all existing data tips within a vector of figure or axis handles.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by