Question
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.
Related Questions
Expert Answer
Kshitij Singh
PhD Expert
Answered Dec 15, 2025
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).
Direct Extraction from .fig Files
This pulls the exact X and Y data from the curves without any approximation.
-
Open the Figure:
matlabopenfig('your_figure.fig'); % Replace with your file name -
Get the Axes and Line Handles:
matlabax = gca; % Get current axes lines = findobj(ax, 'Type', 'line'); % Find all curve lines -
Extract Data:
matlabfor 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- If there are multiple curves, this loops through them.
- For subplots or other elements (e.g., error bars), use findobj with more filters like 'Tag' if set.
- No need to display the figure—run this on a closed file too!
Example output: A matrix of [X Y] pairs you can plot, analyze, or export.
Have a different question? Ask here