How to extract data points from a plot

128 ビュー (過去 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 Center および File ExchangeAnnotations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by