I have a few MATLAB figures, but no MATLAB code associated with it. I want to extract the data from the curves in the figures.
Kshitij Singh answered .
2025-12-15
Yes, you can extract the data from curves in MATLAB figures (.fig files) even without the original code! Since .fig files store the plotted data internally, MATLAB provides easy ways to access it programmatically. I'll cover two main methods: direct extraction (if you have MATLAB access) and digitization tools (if you only have images of the figures).
This pulls the exact X and Y data from the curves without any approximation.
Open the Figure:
openfig('your_figure.fig'); % Replace with your file name
Get the Axes and Line Handles:
ax = gca; % Get current axes
lines = findobj(ax, 'Type', 'line'); % Find all curve lines
Extract Data:
for i = 1:length(lines)
x_data = get(lines(i), 'XData'); % X values for curve i
y_data = get(lines(i), 'YData'); % Y values for curve i
% Display or save
disp(['Curve ' num2str(i) ':']);
disp([x_data(:), y_data(:)]); % Shows as [X Y] matrix
% Optionally save to CSV
writematrix([x_data(:), y_data(:)], ['curve_' num2str(i) '.csv']);
end
Example output: A matrix of [X Y] pairs you can plot, analyze, or export.