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

matfile matfile

文本

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(系统Microsoft®Excel®for Windows®only)

XLTM (import only)
XLTX (import only)

ODS (Systems withMicrosoft Excelfor 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 Column-oriented data in Parquet format parquetread parquetwrite
Data Acquisition Toolbox™ file

DAQ

Data Acquisition Toolbox

daqread

none

Scientific data

提供

Common Data Format

SeeCommon Data Format

Seecdflib

FITS

Flexible Image Transport System

SeeFITS Files

SeeFITS Files

HDF

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

SeeHDF4 Files

SeeHDF4 Files

H5

HDF or HDF-EOS, version 5

SeeHDF5 Files

SeeHDF5 Files

NC

Network Common Data Form (netCDF)

SeeNetCDF Files

SeeNetCDF 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

类风湿性关节炎S

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

audioread audiowrite

any

Formats supported by Microsoft Media Foundation

audioread none

Audio (Mac)

M4A
MP4

mpeg - 4

audioread audiowrite

Audio (Linux®)

any

Formats supported by GStreamer

audioread none

Video(all platforms)

AVI

Audio Video Interleave

VideoReader

VideoWriter

MJ2

Motion JPEG 2000

Video (Windows)

MPG

MPEG-1

VideoReader none

ASF
ASX
WMV

Windows Media®

any

Formats supported by Microsoft DirectShow®

Video (Windows 7or later)

MP4
M4V

mpeg - 4

VideoReader VideoWriter

MOV

QuickTime

VideoReader none

any

Formats supported by Microsoft Media Foundation

Video (Mac)

MP4
M4V

mpeg - 4

VideoReader VideoWriter

MPG

MPEG-1

VideoReader none

MOV

QuickTime

any

Formats supported byQuickTime, including.3gp,.3g2, and.dv

Video (Linux)

any

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

VideoReader none

Triangulation

STL

Stereolithography stlread stlwrite
Low-level files any text format Low-level binary text data fread fwrite
any Low-level binary fscanf fprintf
any text format Formatted data from a text file or string textscan none

Workflows for Specialized Data Formats

Memory-Mapping for Binary Data

For binary data files, consider theOverview 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 withMATLABToolboxes

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, uselow-level I/O functionssuch asfscanforfread. 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