チートシート

MATLAB を使用したデータのインポートとエクスポート​

MATLAB は、さまざまな形式のデータの読み書きに対応しています。本リファレンスでは、よくあるユースケースを紹介していますが、利用可能な機能のすべてを網羅しているわけではありません。​

インポートツール

データのインポートを選択して、インポートツールを起動します。

低水準 I/O

fgetlfscanf のような低水準関数は、I/O を最も細かく制御できます。​

fid = fopen('myfile.txt'); 
data = fscanf(fid,'%f %q'); 
fclose(fid); 

形式仕様​

指定子 出力クラス

符号付き整数

符号なし整数

%d,%d8,…

%u,%u8,…

int32,int8

uint32,uint8

浮動小数点

%f

%f32

double

single

文字列

%s, %q

'TextType'

string

日付時刻

%D,%{fmt}D

datetime

期間

%T,%{fmt}T

duration

カテゴリ

%C

categorical

パターン

%[…]

string

フィールドのスキップ

%*k

 

標準ファイル形式

大きなファイルや複数のファイルにはデータストアを使用してください。fileDatastore はあらゆるタイプのファイルで使用できます。カスタムデータストアを使用すると、読み取り動作をより高度に制御することができます。

専門的な I/O サポートは、いくつかのアドオン製品 (SimulinkDatabase ToolboxVehicle Network Toolbox など) で提供されています。追加機能については、File ExchangeGitHub をご覧ください。

単一ファイル 複数ファイル 書き込み 高度

テキスト

readtable

tabularTextDatastore

writetable

detectImportOptions

textscan

スプレッドシート

readtable

spreadsheetDatastore

writetable

detectImportOptions

.mat

load matfile

fileDatastore

save

Custom datastore

画像

imread

imageDatastore

imwrite

Custom datastore

動画

VideoReader

fileDatastore

VideoWriter

Custom datastore

音声

audioread

fileDatastore

audiowrite

Custom datastore

NetCDF

ncread

fileDatastore

ncwrite

netcdf

CDF

cdfread

fileDatastore

cdfwrite

cdflib

HDF5

h5read

fileDatastore

h5write

H5, H5F, …

XML

xmlread

fileDatastore

xmlwrite

Custom datastore

バイナリ

fread

fileDatastore

fwrite

Custom datastore

Web データ

RESTful Web サービス

webread

データ読み込み

webwrite

データ書き込み

websave

データをファイルに保存

weboptions

認証やタイムアウトなどのオプションを指定

JSON

jsondecode jsonencode

HTTP メッセージング

より複雑な Web 通信には、HTTP インターフェイスをご利用ください。

body = matlab.net.http.MessageBody(x);
request = matlab.net.http.RequestMessage(method,header,body);