Main Content

Supported File Formats for Import and Export

The ideal workflow to import data into MATLAB® depends on how your data is formatted as well as your personal preferences. You can import data programmatically or use a specialized workflow. The most common solution is to import data programmatically using a function tailored for your data.

When you import data into the MATLAB workspace, the new variables you create overwrite any existing variables in the workspace that have the same name.

Importing Files Programmatically

MATLAB includes functions tailored to import specific file formats. Consider using format-specific functions when you want to import an entire file or only a portion of a file. Many of the format-specific functions provide options for selecting ranges or portions of data. Some format-specific functions allow you to request multiple optional outputs.

This table shows the file formats that you can import and export from the MATLAB application.

File Content

Extension

Description

Import Function

Export Function

MATLAB formatted data

MAT

Saved MATLAB workspace

load

save

Partial access of variables in MATLAB workspace

matfilematfile

Text

any, including:
CSV
TXT

Comma delimited numbers

readmatrix

writematrix

Delimited numbers

readmatrix

writematrix

Delimited numbers, or a mix of text and numbers

textscan

none

Column-oriented delimited numbers or a mix of text and numbers

readtable

readcell

readvars

writetable

writecell

Spreadsheet

XLS
XLSX
XLSM

XLSB (Systems with Microsoft® Excel® for Windows® only)

XLTM (import only)
XLTX (import only)

ODS (Systems with Microsoft Excel for Windows only)

Column-oriented data in worksheet or range of spreadsheet

readmatrix

readtable

readcell

readvars

writematrix

writetable

writecell

Extensible Markup Language

XML

XML-formatted text

readstruct

readtable

readtimetable

writestruct

writetable

writetimetable

Parquet formatted dataPARQUETColumn-oriented data in Parquet formatparquetreadparquetwrite
Data Acquisition Toolbox™ file

DAQ

Data Acquisition Toolbox

daqread

none

Scientific data

CDF

Common Data Format

See Common Data Format

See cdflib

FITS

Flexible Image Transport System

See FITS Files

See FITS Files

HDF

Hierarchical Data Format, version 4, or HDF-EOS v. 2

See HDF4 Files

See HDF4 Files

H5

HDF or HDF-EOS, version 5

See HDF5 Files

See HDF5 Files

NC

Network Common Data Form (netCDF)

See NetCDF Files

See NetCDF Files

Image data

BMP

Windows Bitmap

imread

imwrite

GIF

Graphics Interchange Format

HDF

Hierarchical Data Format

JPEG
JPG

Joint Photographic Experts Group

JP2
JPF
JPX
J2C
J2K

JPEG 2000

PBM

Portable Bitmap

PCX

Paintbrush

PGM

Portable Graymap

PNG

Portable Network Graphics

PNM

Portable Any Map

PPM

Portable Pixmap

RAS

Sun™ Raster

TIFF
TIF

Tagged Image File Format

XWD

X Window Dump

CUR

Windows cursor resources

imread

none

ICO

Windows icon resources

Audio (all platforms)

AU
SND

NeXT/Sun sound

audioread

audiowrite

AIFF

Audio Interchange File Format

AIFC

Audio Interchange File Format, with compression codecs

FLAC

Free Lossless Audio Codec

OGG

Ogg Vorbis

WAV

Microsoft WAVE sound

Audio (Windows)

M4A
MP4

MPEG-4

audioreadaudiowrite

any

Formats supported by Microsoft Media Foundation

audioreadnone

Audio (Mac)

M4A
MP4

MPEG-4

audioreadaudiowrite

Audio (Linux®)

any

Formats supported by GStreamer

audioreadnone

Video (all platforms)

AVI

Audio Video Interleave

VideoReader

VideoWriter

MJ2

Motion JPEG 2000

Video (Windows)

MPG

MPEG-1

VideoReadernone

ASF
ASX
WMV

Windows Media®

any

Formats supported by Microsoft DirectShow®

Video (Windows 7 or later)

MP4
M4V

MPEG-4

VideoReaderVideoWriter

MOV

QuickTime

VideoReadernone

any

Formats supported by Microsoft Media Foundation

Video (Mac)

MP4
M4V

MPEG-4

VideoReaderVideoWriter

MPG

MPEG-1

VideoReadernone

MOV

QuickTime

any

Formats supported by QuickTime, including .3gp, .3g2, and .dv

Video (Linux)

any

Formats supported by your installed GStreamer plug-ins, including .ogg

VideoReadernone

Triangulation

STL

Stereolithographystlreadstlwrite
Low-level filesany text formatLow-level binary text datafreadfwrite
anyLow-level binaryfscanffprintf
any text formatFormatted data from a text file or stringtextscannone

Workflows for Specialized Data Formats

Memory-Mapping for Binary Data

For binary data files, consider the Overview of Memory-Mapping. Memory-mapping enables you to access file data using standard MATLAB indexing operations. Memory-mapping is a mechanism that maps a portion of a file, or an entire file, on disk to a range of addresses within an application's address space. The application can then access files on disk in the same way it accesses dynamic memory. The principal benefits of memory-mapping are efficiency, faster file access, the ability to share memory between applications, and more efficient coding.

Specialized Importing with MATLAB Toolboxes

MATLAB toolboxes perform specialized import operations. For example, use Database Toolbox™ software for importing data from relational databases. Refer to the documentation on specific toolboxes to see the available import features.

Web Services for Reading and Writing Data

You can use web services such as a RESTful or WSDL to read and write data in an internet media type format such as JSON, XML, image, or text. For more information, see:

Reading Data with Low-Level IO

If the format-specific functions cannot read your data and the specialized workflows do not fit your needs, use low-level I/O functions such as fscanf or fread. Low-level functions allow the most control over reading from a file, but they require detailed knowledge of the structure of your data. This workflow is not commonly used.

Related Topics