主要内容

Supported File Formats for Import and Export

The ideal workflow to import data into MATLAB®取决于您的数据格式以及您的个人喜好。您可以以编程方式导入数据或使用专门的工作流程。最常见的解决方案是使用为您的数据量身定制的函数以编程方式导入数据。

当您将数据导入MATLAB工作空间时,您创建的新变量覆盖具有相同名称的工作区中的任何现有变量。

Importing Files Programmatically

MATLAB包括针对导入特定文件格式的量身定制的功能。当您想导入整个文件或仅一部分文件时,请考虑使用特定于格式的功能。许多格式特定功能提供了选择范围或数据部分的选项。某些格式特定的功能允许您请求多个可选输出。

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

文件内容

Extension

Description

导入功能

导出功能

MATLAB格式数据

MAT

Saved MATLAB workspace

load

save

Partial access of variables in MATLAB workspace

matfile matfile

Text

任何, including:
CSV
TXT

Delimited numbers

readmatrix

Writematrix

划界数字或文本和数字的混合

textscan

none

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

readtable

readcell

readvars

writetable

Writecell

纯文本

readlines

writelines

Spreadsheet

XLS
XLSX
XLSM

XLSB(系统Microsoft®Excel®for Windows®只要)

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

可扩展标记语言

XML

XML-formatted text

readstruct

readtable

readtimetable

writestruct

writetable

writetimetable

Parquet formatted data PARQUET Column-oriented data in Parquet format parquetread parquetwrite
数据采集​​工具箱™文件

DAQ

数据采集​​工具箱

daqread

none

Scientific data

提供

通用数据格式

See通用数据格式

Seecdflib

FITS

灵活的图像传输系统

See适合文件

See适合文件

HDF

分层数据格式, 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

分层数据格式

JPEG
JPG

Joint Photographic Experts Group

JP2
JPF
JPX
J2C
J2K

JPEG 2000

PBM

Portable Bitmap

PCX

Paintbrush

PGM

便携式灰斑

PNG

便携式网络图形

PNM

便携式任何地图

PPM

Portable Pixmap

Sun™ Raster

tiff
TIF

Tagged Image File Format

XWD

X Window Dump

CUR

Windows cursor resources

imread

none

ICO

Windows icon resources

声音的 (all platforms)

AU
SND

NeXT/Sun sound

audioread

audiowrite

AIFF

Audio Interchange File Format

AIFC

Audio Interchange File Format, with compression codecs

FLAC

免费无损音频编解码器

OGG

Ogg Vorbis

OPUS Ogg Opus

WAV

Microsoft Wave声音

声音的 (Windows)

M4A
MP4

mpeg - 4

audioread audiowrite

任何

Formats supported by Microsoft Media Foundation

audioread none

声音的 (Mac)

M4A
MP4

mpeg - 4

audioread audiowrite

声音的 (Linux®)

任何

GSTREAME万博1manbetxR支持的格式

audioread none

Video(所有平台)

AVI

Audio Video Interleave

录像师

VideoWriter

MJ2

Motion JPEG 2000

视频 (Windows)

MPG

mpeg - 1

录像师 none

ASF
ASX
WMV

Windows Media®

任何

由Microso万博1manbetxft DirectShow支持的格式®

视频 (Windows 7或者later)

MP4
M4V

mpeg - 4

录像师 VideoWriter

MOV

QuickTime

录像师 none

任何

Formats supported by Microsoft Media Foundation

视频 (Mac)

MP4
M4V

mpeg - 4

录像师 VideoWriter

MPG

mpeg - 1

录像师 none

MOV

QuickTime

任何

Formats supported byQuickTime, including。3gp,。3g2, 和。dv

视频 (Linux)

任何

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

录像师 none

Triangulation

STL

Stereolithography StlRead stlwrite
Low-level files 任何text format 低级二进制text data fread fwrite
任何 低级二进制 fscanf fprintf
任何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。内存映射使您可以使用标准MATLAB索引操作访问文件数据。内存映射是一种磁盘上的文件或整个文件的一部分,将其映射到应用程序地址空间中的一系列地址。然后,应用程序可以以访问动态内存的方式在磁盘上访问文件。内存映射的主要好处是效率,更快的文件访问,在应用程序之间共享内存的能力以及更有效的编码。

专门进口MATLAB工具箱

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.

网页服务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:

使用低级IO读取数据

If the format-specific functions cannot read your data and the specialized workflows do not fit your needs, uselow-level I/O functionssuch asfscanf或者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.

相关话题