MATLAB Handle Graphics Tutorial

How to Extract Data from a MATLAB Figure (.fig)

Retrieve Raw X, Y, Z Coordinates, Matrix CData & Subplot Curves

Direct Answer (TL;DR): Open the figure invisibly using fig = openfig('plot.fig', 'reuse', 'invisible');, locate the graphic handle with h = findobj(fig, 'Type', 'line');, and fetch coordinate vectors with x = get(h, 'XData'); y = get(h, 'YData');.
extract_figure_data.m — Handle Graphics Parser 100% Recovered
% 1. Load Figure & Find Line Object Handles
fig = openfig('transient_curve.fig', 'reuse', 'invisible');
h = findobj(fig, 'Type', 'line');
xData = get(h(1), 'XData'); yData = get(h(1), 'YData');

% 2. Export Extracted Vectors to Table & CSV
tbl = table(xData', yData', 'VariableNames', {'Time_s', 'Voltage_V'});
writetable(tbl, 'extracted_data.csv'); % 2,500 Data Points Saved
Figure 1: Extracted Curve Coordinate Reconstruction N = 2,500 Points
Reconstructed Signal (Voltage_V vs Time_s) Sampled (X, Y) Coordinates Time Axis (s)
4.9/5
Student Rating
500+
PhD Experts
100%
Confidential
15k+
Projects Delivered

Step 1: Extract 2D Line Plot Coordinates (X, Y, Z)

If you have a saved MATLAB .fig file but lost the original numerical data arrays, follow this exact script to reconstruct the dataset:

% 1. Open figure invisibly in memory
figHandle = openfig('sample_plot.fig', 'reuse', 'invisible');

% 2. Find all line objects in current axes
lineHandles = findobj(figHandle, 'Type', 'line');

% 3. Extract X, Y, and Z coordinate arrays
xData = get(lineHandles(1), 'XData');
yData = get(lineHandles(1), 'YData');

% 4. Close figure handle safely
close(figHandle);

% Display total points extracted
fprintf('Extracted %d data points successfully.\n', length(xData));

Step 2: Extract Data from Multi-Subplot Figures

When a figure contains multiple subplot panels, locate each axis handle and extract individual curve coordinates:

fig = openfig('multi_subplot.fig', 'reuse', 'invisible');

% Retrieve all axis handles
allAxes = findobj(fig, 'Type', 'axes');
extractedData = struct();

for k = 1:length(allAxes)
    currentLine = findobj(allAxes(k), 'Type', 'line');
    if ~isempty(currentLine)
        extractedData(k).X = get(currentLine(1), 'XData');
        extractedData(k).Y = get(currentLine(1), 'YData');
        fprintf('Subplot %d: Extracted %d points.\n', k, length(extractedData(k).X));
    end
end

close(fig);

Step 3: Extract Matrix Data from Images, Heatmaps & Surface Plots

To retrieve 2D/3D numerical matrix arrays from heatmaps, images, or 3D surfaces, extract the CData or ZData property:

fig = openfig('heatmap_plot.fig', 'reuse', 'invisible');

% Locate image or surface object
imgObj = findobj(fig, 'Type', 'image');
if isempty(imgObj)
    imgObj = findobj(fig, 'Type', 'surface');
end

% Extract raw matrix array
matrixData = get(imgObj(1), 'CData');
close(fig);

disp('Extracted Matrix Dimensions:');
disp(size(matrixData));

Step 4: Export Extracted Data to CSV / Excel / MAT

Format your recovered vectors into a MATLAB table and save to disk for downstream analysis:

% Option A: Export to CSV or Excel
dataTable = table(xData', yData', 'VariableNames', {'Time_Seconds', 'Amplitude'});
writetable(dataTable, 'ExtractedFigureData.csv');

% Option B: Save directly into MAT-file
save('ExtractedDataset.mat', 'xData', 'yData', 'matrixData');
Professional Support

Need Help with MATLAB Data Extraction or Modeling?

Our PhD engineers can reconstruct complex figure data, automate signal processing pipelines, and build complete simulation models.

Submit Requirement WhatsApp Expert
Related Disciplines

Explore Specialised Engineering Services

View All Services →
Clear Answers

Frequently Asked Questions

Common questions regarding MATLAB figure data extraction and handle graphics.

For 3D surface or mesh plots, locate the surface object with h = findobj(fig, 'Type', 'surface'); and retrieve zData = get(h, 'ZData'); alongside XData and YData matrices.

findobj(fig, 'Type', 'line') returns an array of handles corresponding to each individual plotted line. You can loop through each handle h(i) and extract their respective DisplayName, Color, and coordinate arrays.

Standard .fig files preserve full handle graphics hierarchy. If the figure was compiled into a standalone executable or saved with hidden handles, our engineering team can use custom deserialization routines to recover the underlying data.