Main Page EEng School DCU

Matlab 2 Scilab Portation

In some ways, Scilab may be the "best" of the Matlab clones. Scilab has many strengths, including excellent documentation (the signal processing manual is an education in itself) and excellent support (via e-mail and its own newsgroup). Best of all, for Windows users, Scilab is supplied not only as source code, but as a Windows binary. Scilab is mostly, but not completely, compatible with Matlab. Scilab now comes with a Matlab-to-Scilab translator, but that's still a bit immature. Its name is mfile2sci. There is another converter, translatepaths,to translate a set of Matlab m_file directories to Scilab. They can both be invoked in Scilab command window.


MFILE2SCI

CALLING SEQUENCE :

mfile2sci(M_file_path [,result_path [,Imode [,Recmode]]])

PARAMETERS :

M_file_path : a character string which gives the path of Matlab M_file to translate
result_path : a character string which gives the directory where the result has to be written. Default value is current directory.
Imode : Boolean flag, If true mfile2sci ask user for variable type and sizes when he cannot infer them. Default value : %f
Recmode : Boolean flag, used by translatepaths function. Must be %f to translate a single mfile.

DESCRIPTION :

mfile2sci, is Matlab M-file to Scilab function traduction tools. It tries whenever possible to replace call to Matlab functions by the equivalent scilab primitives and functions. To translate 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

<function_name>.sci : the scilab equivalent of the m_file
<function_name>.cat : the scilab help file associated to the function
sci_<function_name>.sci : the scilab function required to translate the calls to this Matlab M_file in other Matlab M_files. this function may be improved "by hand".

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.

Some other functions like plot, has no straightforward translation 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 began by "//!"

REMARKS :

This function is a still under developpement and is delivered as beta test.
Some Matlab4 basic functions are not yet translated. It is quite simple to add it. See <SCIDIR>/macros/m2sci/README for more details.

KNOWN BUGS :

1- : m_files scripts are translated but sci_<Matlab function name> replaces the call to the m_file by an exec of an exec (.sce) file, the .sce file path may be incorrect.
2- : eval function instructions passed as strings are not translated.
3- : most of plot function are not yet translated
4- : globals are not translated
5- : if, for, endded by the end of file produce an error, add the closing end's
6- : Loop variable of for clause is available afterwards if loops terminates normally in matlab; it is cleared in Scilab generated code.
7- : inequality comparison which implies complex numbers produce a run time error such as "undefined variable : %s_2_s". User can define these operation with Matlab meaning with the following function definition:

deff('r=%s_1_s(a,b)','r=real(a)<real(b)')

deff('r=%s_2_s(a,b)','r=real(a)>real(b)') deff('r=%s_3_s(a,b)','r=real(a)<=real(b)') deff('r=%s_4_s(a,b)','r=real(a)>=real(b)')

8- : When i is a vector, Matlab allows insertions like a(i)=v for any v. In scilab v must have the same shape as a(i). This produces run time errors "submatrix incorrectly defined". Rewrite them as a(i)=v.' .

EXAMPLE :

In the Scilab command window (Scilab does not have any integrated editor!!!) type the below lines. Unfortunately, this is the only was to write a code file in Scilab.

//remove any test.m, test.sci, sci_Fibno.sci, test.cat files from the C:/Temp directory!
//create a simple m_file
write('C:/Temp/'+'test.m',['% An M-file to calculate Fibonnaci numbers'
'function f = Fibno()'
'f=[1 1]; i=1;'
'while f(i) + f(i+1) < 1000'
'  f(i+2)=f(i)+f(i+1);'
' i=i+1;'
'end'
'plot(f)']);
 
 

// translate it to scilab
mfile2sci('C:/Temp/'+'test.m','C:/Temp')
// show the new code
write(%io(2),read('C:/Temp/'+'test.sci',-1,1,'(a)'))
// get it into scilab
getf('C:/Temp/'+'test.sci')
//execute it
Fibno()


TRANSLATEPATHS

CALLING SEQUENCE :

translatepaths(dirs_path [,res_path])

PARAMETERS :

dir_path : a character string vector which gives the paths of Matlab M_file directories to translate
res_path : a character string which gives the path of the directory where the scilab functions are written to.

DESCRIPTION :

translatepaths, translate all Matlab M-file contained in a set of directories to Scilab functions. Each function is translated by mfile2sci.
 


Valentin Muresan, Dublin City University, muresanv@eeng.dcu.ie