Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: English - Français - Português - Русский
Scilabヘルプ >> Matlab binary files I/O > savematfile

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のデータ型に変換されます.

  • Unsupported Scilab data types: polynomials, rationals, lists, all tlists and mlists, primitives, functions, libraries, graphics, implicit lists (like 2:$)

  • v4: For any hypermatrix h, its pages are horizontally concatenated before saving the resulting matrix: h = matrix(h, size(h,1), -1).

  • ASCII:

    • The imaginary part of complex numbers is ignored (dense and sparse).
    • Booleans are stored as 0.|1. (dense and sparse).

Data type v4v6v7v7.3ASCII Comments
booleanxbugbugbugx Bug 15568
integerxXXXno int8 are stored as uint8 if they are all > 0, or as int16 otherwise.
uint32 are stored as int32 if they are all < 231-1, or as decimal numbers otherwise.
int64 and uint64 are stored as decimal numbers.
realxXXXx
complexxXXXx ASCII: imaginary part ignored.
sparse xx x x x Octave 4.4 loads correctly any real or complex sparse array saved from Scilab 6.0.
But loadmatfile() crashes Scilab for any sparse saved with -v4, and any complex sparse saved with -v6 -v7 or -v7.3.
boolean sparsexnononox v4: Saved as sparse decimal 0|1. Well read from Octave 4.4
Textx? v4: Any array is saved as a column of texts right-padded with spaces to all have the same lengths.
structnoxXno
cellnoXXXno 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, "text",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]
  text: [2x1 string]
  int: [4x10 int8]

 C =
  [  1x1 string  ]  [2x3 constant]
  [2x4x2 constant]  [1x1 struct  ]

参照

  • loadmatfile — lMatlab V6 MATファイル (バイナリまたは ASCII) を Scilabに読み込む
  • 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

Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Feb 14 15:02:37 CET 2019