How do I extract data points from a plot?

M
Mariahernandez01 · Apr 3, 2020 · 2.4K views
Question
I would like to extract data points from a plot.
Expert Answer
Profile picture of Prashant Kumar
Prashant Kumar PhD Expert
Answered Sep 3, 2026

You can extract data points from a plot in MATLAB even if you don't have access to the original data. Here are the steps to do this:

  1. Open the Figure: If the figure is saved as a .fig file, use the openfig function. If the figure is already open, use gcf to get the current figure handle.

  2. Access the Plot Data: Use the Children property to access the axes and data objects.

  3. Retrieve the Data: Extract the XData and YData properties from the data objects.

Here’s an example:

matlab
% Open the figure file (replace 'your_figure.fig' with your actual file name)
fig = openfig('your_figure.fig');

% Alternatively, if the figure is already open
% fig = gcf;

% Get the axes objects
axObjs = fig.Children;

% Get the data objects within the axes
dataObjs = axObjs.Children;

% Extract XData and YData from the first data object (assuming it's a Line object)
x = dataObjs(1).XData;
y = dataObjs(1).YData;

% Display the extracted data
disp('X Data:');
disp(x);
disp('Y Data:');
disp(y);

This code extracts the XData and YData from the first plotted line in the figure. If there are multiple lines or data objects, you can loop through dataObjs to extract data from each one.

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!