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 | ||
Partial access of variables in MATLAB workspace | matfile | matfile | ||
Text | any,
including: | Delimited numbers | ||
Delimited numbers, or a mix of text and numbers | none | |||
Column-oriented delimited numbers or a mix of text and numbers | ||||
Plain text | ||||
Spreadsheet | XLS XLSB (Systems with Microsoft® Excel® for Windows® only) XLTM (import
only) ODS (Systems with Microsoft Excel for Windows only) | Column-oriented data in worksheet or range of spreadsheet | ||
Extensible Markup Language | XML | XML-formatted text | ||
JavaScript® Object Notation | JSON | JSON-formatted text | ||
Parquet formatted data | PARQUET | Column-oriented data in Parquet format | parquetread | parquetwrite |
Data Acquisition Toolbox™ file | DAQ | Data Acquisition Toolbox | none | |
Scientific data | CDF | Common Data Format | See | |
FITS | Flexible Image Transport System | See FITS Files | See FITS Files | |
HDF | HDF4 or HDF-EOS2 | See HDF4 Files | See HDF4 Files | |
H5 | HDF5 | See HDF5 Files | See HDF5 Files | |
NC | Network Common Data Form (netCDF) | See NetCDF Files | See NetCDF Files | |
Image data | BMP | Windows Bitmap | ||
GIF | Graphics Interchange Format | |||
HDF | Hierarchical Data Format | |||
JPEG | Joint Photographic Experts Group | |||
JP2 | 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 | Tagged Image File Format | |||
XWD | X Window Dump | |||
CUR | Windows cursor resources | none | ||
ICO | Windows icon resources | |||
Audio (all platforms) | AU | NeXT/Sun sound | none | |
AIFF | Audio Interchange File Format | |||
AIFC | Audio Interchange File Format, with compression codecs | |||
FLAC | Free Lossless Audio Codec | |||
MP3 | MPEG-1 Audio Layer III | |||
OGG | Ogg Vorbis | |||
OPUS | Ogg Opus | |||
WAV | Microsoft WAVE sound | |||
Audio (Windows) | M4A | MPEG-4 Part 3 AAC | ||
any | Formats supported by Microsoft Media Foundation | none | ||
Audio (Mac) | M4A | MPEG-4 Part 3 AAC | ||
Audio (Linux®) | any | Formats supported by GStreamer | none | |
Video (all platforms) | AVI | Audio Video Interleave | ||
MJ2 | Motion JPEG 2000 | |||
Video (Windows) | MPG | MPEG-1 | VideoReader | none |
ASF | Windows Media® | |||
any | Formats supported by Microsoft DirectShow® | |||
Video (Windows 7 or later) | MP4 | MPEG-4 | VideoReader | VideoWriter |
MOV | QuickTime® | VideoReader | none | |
any | Formats supported by Microsoft Media Foundation | |||
Video (Mac) | MP4 | MPEG-4 | VideoReader | VideoWriter |
MPG | MPEG-1 | VideoReader | none | |
MOV | QuickTime | |||
any | Formats supported by QuickTime, including | |||
Video (Linux) | any | Formats supported by your installed GStreamer plug-ins,
including | 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 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.