Need to convert graphs (.fig format) into .csv format
Mostra commenti meno recenti
Hi, I have this image containing multiple graphs, how do I obtain the data of the graphs into a .csv file?
Thanks in advance.
Risposte (1)
Aashray
il 29 Ago 2025
You can extract the numeric data from a “.fig” file by reopening it in MATLAB, finding the line objects, and saving their “XData” and “YData” to a “.csv”. To illustrate the process, I have first created a sample figure and saved it as “.fig”, reopened it and exported the data.
Step 1: Create and save a “.fig” file
% Create dummy data
x = 0:50;
y1 = 70 + 10*sin(0.1*x) + randn(size(x)); % noisy sine-like curve
y2 = 80 + 15*exp(-0.02*(x-25).^2); % Gaussian bump
y3 = 90 + 5*randn(size(x)); % random fluctuations
% Create figure and plot multiple lines
figure;
plot(x, y1, 'm-s','LineWidth',1.5); hold on
plot(x, y2, 'y-^','LineWidth',1.5);
plot(x, y3, 'b-d','LineWidth',1.5);
grid on
xlabel('X axis');
ylabel('Y values');
title('Dummy Multi-Line Figure');
legend('Series 1','Series 2','Series 3','Location','best');
% Save the figure in .fig format
savefig('dummy_figure.fig');
This gives you a “.fig” file similar to the one in your screenshot.

Step 2: Open the “.fig” and export its data to “.csv”
% Load the .fig file
fig = openfig('dummy_figure.fig','invisible'); % open without displaying
% Find all line objects in the figure
hLines = findall(fig, 'Type', 'Line');
% Prepare a cell array to hold all series
numLines = numel(hLines);
maxLen = max(arrayfun(@(h) numel(h.XData), hLines));
data = NaN(maxLen, numLines*2); % columns: X1 Y1 X2 Y2 ...
% Loop through each line and extract X/Y
for k = 1:numLines
x = hLines(k).XData(:);
y = hLines(k).YData(:);
data(1:numel(x),(2*k-1)) = x;
data(1:numel(y),(2*k)) = y;
end
% Write to CSV
csvwrite('extracted_data.csv', data);
% close figure
close(fig)

This way you can easily pull out the raw line data from any “.fig” file and save it for use in “.csv” format.
You may refer to documentation links for the functions used in the above implementation:
Categorie
Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!