Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.0 - Français

Change language to:
English - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function

Aide de Scilab >> Matlab : fichiers données (R/W) > savematfile

savematfile

saves some Scilab variables in a Matlab MAT-file (binary or ASCII)

Syntax

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)

Arguments

filename

character string containing the path+name of the file

varnames

vector of the names (text) of variables to save, like ["var1" "var2"..].

"var1", "var2"...

character strings being the names of the variables to save.

format

data format to use

"-mat" : binary MAT-file (default)
"-v4" : A format that MATLAB Version 4 can open
"-v6" : A format that MATLAB Version 6 and earlier can open
"-v7" : A format that MATLAB Version 7 and earlier can open (default)
"-v7.3" : A format that MATLAB Version 7.3 and earlier can open
"-ascii" : 8-bit ASCII format
"-ascii" "-double" : 16-bit ASCII format
"-ascii" "-tabs" : delimits with tabs
"-ascii" "-double" "-tabs" : 16-digit ASCII format, tab delimited

"-struct" "s"

saves all fields of the scalar structure s as individual variables within the file filename.

"-struct" "s" "f1" "f2"

saves as individual variables only those structure fields specified (s.f1, s.f2, ...).

Description

Saves some Scilab variables in a Matlab MAT-file. The names of chosen variables may be provided as distinct input arguments, or through a vector of names. By default, all variables existing in the workspace are saved. The Scilab data types are converted into the Matlab equivalents.

  • 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

Examples

// 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  ]

See also

  • loadmatfile — loads some variables from an Octave or a Matlab MAT binary or ASCII data file
  • matfile2sci — convertit un fichier Matlab .mat en un fichier binaire Scilab
  • mfile2sci — Fonction de conversion de fichiers.m Matlab en langage Scilab
  • save — Saves some chosen variables in a binary data file
  • load — Loads some archived variables, a saved graphic figure, a library of functions

Bibliography

This function has been developed following the "MAT-File Format" description: Mat-File Format

Report an issue
<< matfile_varwrite Matlab : fichiers données (R/W) Code Matlab => Scilab >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 25 08:50:45 CET 2020