Importing and Exporting Data Using MATLAB
MATLAB provides functionality to read and write data in many forms. This reference shows common use cases, but is not a comprehensive list of available functionality.
Import Tool
Select Import Data to launch the Import Tool.
Low Level I/O
Low-level functions, such as fgetl and fscanf, allow the most control over I/O.
fid = fopen('myfile.txt');
data = fscanf(fid,'%f %q');
fclose(fid);
Format Specs
| Type | Specifier | Output Class |
|---|---|---|
Signed int Unsigned int |
|
|
| Floating point |
|
|
Text array |
|
|
Datetime |
|
|
Duration |
|
|
Category |
|
|
Pattern |
|
|
Skip field |
|
|
Standard File Formats
Use datastores for large or multiple files. fileDatastore can be used with any type of file. Use a custom datastore for more advanced control over read behavior.
Specialized I/O support can be found in several add-on products (Simulink, Database Toolbox, Vehicle Network Toolbox , and others. See the File Exchange and GitHub for additional functionality.
| Type | Single File | Multiple Files | Write | Advanced |
|---|---|---|---|---|
Text |
|
|
|
|
Spreadsheet |
|
|
|
|
.mat |
|
|
|
|
Image |
|
|
|
|
Video |
|
|
|
|
Audio |
|
|
|
|
NetCDF |
|
|
|
|
CDF |
|
|
|
|
HDF5 |
|
|
|
|
XML |
|
|
|
|
Binary |
|
|
|
|
RESTful Web Service
|
Read data |
|
Write data |
|
Save data to file |
|
Specify options such as authentication and timeout |
JSON
jsondecode |
jsonencode |
HTTP Messaging
Use the HTTP interface for more complex web communication.
body = matlab.net.http.MessageBody(x); request = matlab.net.http.RequestMessage(method,header,body);