How to get data points from graph

32 views (last 30 days)
hi,
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.
Regards,
Syed Mohiuddin
  2 Comments
Dyuman Joshi
Dyuman Joshi on 1 Dec 2023
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 on 1 Dec 2023
i want to have x and y coordinates values from the graph
Regards,
Syed Mohiuddin

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 1 Dec 2023
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
figure
plot(x, y, '-r', 'LineWidth',2)
grid
xlabel('x')
ylabel('y')
title('Recovered Data')
axis('equal') % Optional
.
  11 Comments
Syed Mohiuddin
Syed Mohiuddin on 2 Dec 2023
Thank you thank you thank you, great, this was exactly what i wanted.

Sign in to comment.

More Answers (1)

Mathieu NOE
Mathieu NOE on 1 Dec 2023
Edited: Voss on 1 Dec 2023
hello
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);
figure(1)
plot(x,y);
  3 Comments
Mathieu NOE
Mathieu NOE on 4 Dec 2023
you probably did not download the function with the link I mentionned above
for your convenience I attach here to this post

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!