필터 지우기
필터 지우기

How to extract data points from a plot

조회 수: 157 (최근 30일)
Rose Sohyun Ahn
Rose Sohyun Ahn 2022년 2월 2일
댓글: Dave B 2023년 2월 3일
Hello,
I'm doing homework through matlab and I'm trying to find certain points that will fit my answer through matlab plotting. Is there a way I can click on the graph and extract x and y data points arbitrarily?
Thank you !
I have attached my very simple code for clarification.

답변 (1개)

Dave B
Dave B 2022년 2월 2일
To interactively select points to export data to the workspace, there are a couple of options - using datatips is great for single points, data brushing works better for multiple points:
One point
For most MATLAB plots, you'll see a little box (called a datatip) when you hover over points. If you click while a point is highlighted, the box stays put when you move your mouse away. If you then right click you'll see an option to "Export Cursor Data to Workspace"
Multiple Points
When you hover over the axes a little toolbar shows up in the upper right corner. One of the options in that toolbar looks like a little paintbrush. Turn this on to activate "DataBrushing" mode. You can click and drag to select some points you'd like to export. When you've selected the points you want, disable brushing (by clicking the paintbrush again) and right click somewhere on the axes. You'll see an option to Export Brushed, which will export a variable containing the data points.
  댓글 수: 4
Ali
Ali 2023년 1월 20일
It works, thank you!
In the first method , can we get the x and y coordinates seperately instead of getting them in a [x,y] format?
further, there is also a column called "data index". is that related to the order of the data points?
does it indicate which data was plotted before the other one?
Dave B
Dave B 2023년 2월 3일
@Ali -
I don't think there's a setting that will return the coordinates in separate variables, although it's pretty easy to move between vectors and variables.
x=cursor_info.Position(1);
y=cursor_info.Position(2);
If you had multiple datatips and wanted to grab all of them at once, you might do something like:
xy=vertcat(cursor_info.Position)
x=xy(:,1);y=xy(:,2);
Note that some plots (like surf or contour) might have a third dimension.
I think the DataIndex is the index into XData/YData properties, which corresponds to the order that you passed them into plot, but I'm not sure if that's your question. This might be a little more complicated if you don't have the "Snap to Nearest Data Vertex" option selected in Selection Style.

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by