How to get data points from graph

조회 수: 29 (최근 30일)
Syed Mohiuddin
Syed Mohiuddin 2023년 12월 1일
댓글: Syed Mohiuddin 2023년 12월 7일
I have graph, i need to prepare a table of the data for x and y terms. How should i get the data points from the enclosed graph, please let me know.
Syed Mohiuddin
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2023년 12월 1일
It's not clear to me what you want to do.
What does 'terms' mean here?
Do you want to x and y coordinate values of the points used to plot that graph from the figure?
Syed Mohiuddin
Syed Mohiuddin 2023년 12월 1일
i want to have x and y coordinates values from the graph
Syed Mohiuddin

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

채택된 답변

Star Strider
Star Strider 2023년 12월 1일
Getting information from .fig files has changed over the years. This approach works with the most recent releases.
Use the findobj function with the axes handle to return specifc ‘Line’ objects (since there may be more than one), then index into them, for example:
Lines = findobj(Ax, 'Type','line')
X{1} = Lines(1).XData;
Y{1} = Lines(1).YData;
If there are more than one, this can be done in a loop.
There is only one here, so just do this —
openfig('data points.fig');
% Ax = hf.CurrentAxes; % One Option
Ax = gca; % Another Option
Lines = findobj(Ax, 'Type','line'); % Return Handles To All 'Line' Objects
x = Lines.XData % Independent Variable
x = 1×50
-1.0000 -0.9592 -0.9184 -0.8776 -0.8367 -0.7959 -0.7551 -0.7143 -0.6735 -0.6327 -0.5918 -0.5510 -0.5102 -0.4694 -0.4286 -0.3878 -0.3469 -0.3061 -0.2653 -0.2245 -0.1837 -0.1429 -0.1020 -0.0612 -0.0204 0.0204 0.0612 0.1020 0.1429 0.1837
y = Lines.YData % Dependent Variable
y = 1×50
0 0.0072 0.0143 0.0211 0.0278 0.0343 0.0407 0.0468 0.0528 0.0587 0.0643 0.0698 0.0752 0.0803 0.0852 0.0900 0.0946 0.0989 0.1030 0.1069 0.1106 0.1140 0.1171 0.1200 0.1225 0.1247 0.1266 0.1281 0.1293 0.1300
plot(x, y, '-r', 'LineWidth',2)
title('Recovered Data')
axis('equal') % Optional
  댓글 수: 11
Syed Mohiuddin
Syed Mohiuddin 2023년 12월 2일
Thank you thank you thank you, great, this was exactly what i wanted.
Star Strider
Star Strider 2023년 12월 2일
As always, my pleasure!

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

추가 답변 (1개)

Mathieu NOE
Mathieu NOE 2023년 12월 1일
편집: Voss 2023년 12월 1일
the main code is very simple (use the attached function - credits to his creator !)
data = extract_data_from_figures('data points.fig');
VN = data.names; % variable names
data = data.Y;
x = data(:,1);
y = data(:,2);
  댓글 수: 3
Mathieu NOE
Mathieu NOE 2023년 12월 4일
you probably did not download the function with the link I mentionned above
for your convenience I attach here to this post
Syed Mohiuddin
Syed Mohiuddin 2023년 12월 7일
Thank you

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


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