savematfile
Matlab MATファイル (バイナリまたは ASCII)を書き込む
呼び出し手順
savematfile('filename') savematfile('filename', varnames, ...) savematfile('filename', 'var1', 'var2', ...) savematfile filename var1 var2 ... savematfile('filename', '-struct', 's') savematfile('filename', '-struct', 's', 'f1', 'f2', ...) savematfile(..., format)
引数
- filename
ファイルへのパスを有する文字列 (必須)
- varnames
変数
["var1" "var2" ..]のように、保存する変数の名前(テキスト)のベクトル.- var1, var2
読み込む変数の名前を有する文字列 (バイナリファイル専用)
- format
使用するデータ形式
"-mat" : バイナリMATファイル (デフォルト) "-v4" : MATLABバージョン4がオープンできる形式 "-v6" : MATLABバージョン6以降がオープンできる形式 "-v7" : MATLABバージョン7以降がオープンできる形式 (デフォルト) "-v7.3" : MATLABバージョン7.3以降がオープンできる形式 "-ascii" : 8ビット ASCII形式 "-ascii" "-double" : 16ビット ASCII形式 "-ascii" "-tabs" : タブ区切り形式 "-ascii" "-double" "-tabs" : 16桁アスキー形式, タブ区切り形式 - "-struct" "s"
スカラー構造体 s の全てのフィールドを ファイル filename の独立した変数として保存.
- "-struct" "s" "f1" "f2"
構造体の指定したフィールド(s.f1, s.f2, ...)のみ独立した変数として保存.
説明
Scilabから Matlab MATファイルに変数を保存します. Scilabのデータ型は 等価なMatlabのデータ型に変換されます.
![]() |
|
| Data type | v4 | v6 | v7 | v7.3 | ASCII | Comments |
|---|---|---|---|---|---|---|
| boolean | X | X | X | X | X | |
| integer | X | X | X | X | no | int8 are stored as uint8 if they are all > 0, or as int16 otherwise. |
| real | X | X | X | X | X | |
| complex | X | X | X | X | X | ASCII: imaginary part ignored. |
| sparse | X | X | X | X | X | Octave 4.4 loads correctly any real or complex sparse array saved from Scilab 6.0. |
| boolean sparse | X | no | no | no | X | v4: Saved as sparse decimal 0|1. Well read from Octave 4.4 |
| character string | X | ? | v4: Any array is saved as a column of character strings right-padded with spaces to all have the same lengths. | |||
| struct | no | X | X | no | ||
| cell | no | X | X | X | no | Must not contain components of unsupported type or yielding errors/crashs |
例
// Preparing some data: H = rand(2,4,2); N = complex(rand(2,3), rand(2,3)); I = int8(grand(4,10,"uin",-100,100)); T = ["foo" "bar"]'; S = struct("num",H, "imag",N, "str",T, "int",I); C = {"Scilab", rand(2,3); H, S}; // Saving them in v7.3 format: File = TMPDIR+"/savematfile_example.mat"; varnames = ['H','N','I','T','S','C']; savematfile(File,'-v7.3', varnames); clear C H I N S T // Recovering data saved in Matlab format: loadmatfile(File); // Displaying them: for v = varnames, execstr("mprintf(""\n %s ="",v); disp("+v+")"), end
--> clear C H I N S T
--> // Recovering data saved in Matlab format:
--> loadmatfile(File);
--> // Displaying them:
--> for v = varnames, execstr("mprintf(""\n %s ="",v); disp("+v+")"), end
H =
(:,:,1)
0.2113249 0.0002211 0.6653811 0.8497452
0.7560439 0.3303271 0.6283918 0.685731
(:,:,2)
0.8782165 0.5608486 0.7263507 0.5442573
0.068374 0.6623569 0.1985144 0.2320748
N =
0.2312237 + 0.2146008i 0.8833888 + 0.3616361i 0.3076091 + 0.5664249i
0.2164633 + 0.312642i 0.6525135 + 0.2922267i 0.9329616 + 0.4826472i
I =
100 51 -52 92 17 34 -94 -30 36 -30
-70 -72 -9 -19 -78 -15 1 -53 -23 91
76 -83 93 -23 63 -80 -69 86 -7 57
25 31 58 -64 -96 -9 -70 -4 -66 -34
T =
!foo !
!bar !
S =
num: [2x4x2 constant]
imag: [2x3 constant]
str: [2x1 string]
int: [4x10 int8]
C =
[ 1x1 string ] [2x3 constant]
[2x4x2 constant] [1x1 struct ]
参照
- loadmatfile — loads some variables from an Octave or a Matlab MAT binary or ASCII data file
- matfile2sci — converts a Matlab 5 MAT-file into a Scilab binary file
- mfile2sci — Matlab M-file to Scilab conversion function
- save — Saves some chosen variables in a binary data file
- load — Loads some archived variables, a saved graphic figure, a library of functions
参考文献
この関数は以下の "MAT-File Format"に基づき開発されました:
Mat-File Format
| Report an issue | ||
| << matfile_varwrite | Matlab binary files I/O | Code Matlab => Scilab >> |
