Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

matlab_convert_fig.m - Convert MATLAB .fig files to PNG format

Description

This script automatically converts all MATLAB figure files (.fig) in the current working directory to PNG format. It preserves the original filename and creates corresponding .png files.

Usage

From within MATLAB

>> matlab_convert_fig

From command line

matlab -batch "cd('path/to/fig/files'); matlab_convert_fig"

Input

Output

Behavior

Dependencies

Important Note

⚠️ Warning: This script will exit MATLAB upon completion. Use with caution in interactive sessions.

How It Works

  1. File Discovery: Scans current directory for all .fig files

  2. File Processing: For each .fig file:

    • Opens the figure using openfig()

    • Extracts the base filename without extension

    • Saves each figure in the file as PNG using saveas()

  3. Cleanup: Automatically exits MATLAB when all conversions are complete

Example Workflow

# Navigate to directory with .fig files
cd /path/to/figures

# Run conversion (will exit MATLAB when done)
matlab -batch "matlab_convert_fig"

# Results: all .fig files converted to .png

This tool is particularly useful for batch conversion of MATLAB figures to a more portable PNG format for inclusion in reports or presentations.