Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.0.0 - 日本語

Change language to:
English - Français - Português - Русский

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

Scilabヘルプ >> Matlab to Scilab Conversion Tips > mfile2sci


Matlab M-file to Scilab conversion function


mfile2sci([M-file-path [,result-path [,Recmode [,only-double [,verbose-mode [,prettyprintoutput]]]]]])



a character string which gives the path of Matlab M-file to convert


a character string which gives the directory where the result has to be written. Default value is current directory.


Boolean flag, used by translatepaths function for recursive conversion. Must be %F to convert a single mfile. Default value : %f


Boolean flag, if %T mfile2sci considers that numerical function have been used only with numerical data (no Scilab overloading function is needed). Default value: %T


display information mode


no information displayed


information written as comment is resulting SCI-file


information written as comment is resulting SCI-file and in logfile


information written as comment is resulting SCI-file, in logfile and displayed in Scilab window


Boolean flag, if %T generated code is beautified. Default value: %F


M2SCI (and particularly mfile2sci) is Matlab M-file to Scilab function conversion tools. It tries whenever possible to replace call to Matlab functions by the equivalent Scilab primitives and functions.

To convert a Matlab M-file just enter the Scilab instruction: mfile2sci(file)

where file is a character string giving the path name of the M-file mfile2sci will generate three files in the same directory


the Scilab equivalent of the M-file


the Scilab help file associated to the function


the Scilab function required to convert the calls to this Matlab M-file in other Matlab M-files. This function may be improved "by hand". This function is only useful for conversion not for use of translated functions.

Some functions like eye, ones, size, sum,... behave differently according to the dimension of their arguments. When mfile2sci cannot infer dimensions it replaces these function call by a call to an emulation function named mtlb_<function_name>. For efficiency these functions may be replaced by the proper scilab equivalent instructions. To get information about replacement, enter: help mtlb_<function_name> in Scilab command window

Some other functions like plot, has no straightforward �quivalent in scilab. They are also replaced by an emulation function named mtlb_<function_name>.

When translation may be incorrect or may be improved mfile2sci adds a comment which begins by "//!" (according to verbose-mode)

When called without rhs, mfile2sci() launches a GUI to help to select a file/directory and options.


// Create a simple M-file
rot90m = ["function B = rot90(A,k)"
    "if ~isa(A, ''double'')"
    "    error(''rot90: Wrong type for input argument #1: Real or complex matrix expected.'');"
    "    return"
    "[m,n] = size(A);"
    "if nargin == 1"
    "    k = 1;"
    "    if ~isa(k, ''double'')"
    "        error(''rot90: Wrong type for input argument #2: A real expected.'');"
    "        return"
    "    end"
    "    k = rem(k,4);"
    "    if k < 0"
    "        k = k + 4;"
    "    end"
    "if k == 1"
    "    A = A.'';"
    "    B = A(n:-1:1,:);"
    "elseif k == 2"
    "    B = A(m:-1:1,n:-1:1);"
    "elseif k == 3"
    "    B = A(m:-1:1,:);"
    "    B = B.'';"
    "    B = A;"
mputl(rot90m, TMPDIR + "/rot90.m")

// Convert it to scilab
mfile2sci(TMPDIR + "/rot90.m",TMPDIR)

// Show the new code
mgetl(TMPDIR + "/rot90.sci")

// Load it into scilab

// Execute it

See also

  • translatepaths — convert a set of Matlab M-files directories to Scilab
Report an issue
<< Matlab-Scilab_character_strings Matlab to Scilab Conversion Tips Operation >>

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 14 15:10:43 CET 2017