FromMFile - Maple Help

Matlab

 FromMFile
 translate a MATLAB(R) .m source code file to Maple code

 Calling Sequence FromMFile(mfile) FromMFile(mfile,mplfile) FromMFile(mfile,mwfile) FromMFile(mfile, ..., evaluate = false ) FromMFile(mfile, ..., overwrite = true ) FromMFile(mfile, ..., path = [paths] ) FromMFile(mfile, ..., string = false ) FromMFile(mfile, ..., worksheet = false ) FromMFile(mfile, ..., AddTranslator = false )

Parameters

 mfile - string specifying source .m file mplfile - (optional) string specifying target command (.mpl) file mwfile - (optional) string specifying target worksheet (.mw) file evaluate - (optional) truefalse (default is false) overwrite - (optional) truefalse (default is true) path = paths - (optional) string or list of strings string - (optional) truefalse worksheet - (optional) truefalse AddTranslator - (optional) truefalse

Description

 • FromMFile converts a MATLAB® .m file into equivalent Maple input. The form of the converted output is controlled by one or more optional parameter.
 • When only one argument is given, FromMFile displays the code translation and evaluates it.  Specifying the evaluate option will execute the translated code without first displaying the translated code.  Specifying the string option will leave the translation as an unparsed string. It is recommended that translated code be reviewed first before evaluating it.
 • The second argument to FromMFile is the name of an output file. The target output can be a Maple worksheet file (.mw), or a Maple command file (.mpl).  A worksheet file can be opened via File->Open in Maple's graphical user interface.  A command file can be executed via Maple's read command.
 • When the second argument is a file name that ends in .mw, the output format is assumed to be Maple's xml worksheet format.  To write a worksheet to a file name that doesn't end in .mw use the worksheet option.  Similarly, use worksheet = false to write a command file using the extension .mw (but we don't recommend doing this).
 • By default overwrite is set to true.  Thus, if the target mwfile or mplfile already exists, it will be silently overwritten.  Specify overwrite = false to disallow writing over an existing file.
 • FromMFile will identify functions that are referenced in the current file, but implemented in a separate file.  Consider the following two files:

 % file r1.m: reference example 1/2 function [r] = r1( a, b ) r = r2(a)  r3(b)

 % file r2.m: reference example 2/2 function [r] = r2( a ) r = 2a

Executing FromMFile("r1.m",string) will show you that r2 was also translated in the same pass.  The path option controls where the translator looks to find other .m files that implement commands referenced by the current .m file.  By default the directory that contains mfile is in the search path.  Setting path=[] prevents the translator from looking at any other file. One or more directories can be specified in the path= list.

 • When the AddTranslator option is set to false, the translator bypasses the AddTranslator extension mechanism and gives a general MATLAB® to Maple syntax translation without attempting to interpret the meaning of MATLAB® function calls.
 • For further discussion on MATLAB® to Maple translation see FromMatlab.
 • This function is part of the Matlab package, so it can be used in the short form FromMFile(..) only after executing the command with(Matlab).  However, it can always be accessed through the long form of the command by using Matlab[FromMFile](..).

Examples

 > $\mathrm{with}\left(\mathrm{Matlab}\right):$
 > $\mathrm{mfile}≔\mathrm{cat}\left(\mathrm{kernelopts}\left(\mathrm{datadir}\right),"/help/Matlab/r1.m"\right):$
 > $\mathrm{FromMFile}\left(\mathrm{mfile},'\mathrm{string}','\mathrm{path}'=\left[\right]\right)$
 ${"r1 := proc\left( a, b \right) local r; # file r1.m ?FromMfile function reference example 1/2 r := r2\left(a\right) . r3\left(b\right); return r; end proc;"}$ (1)
 > $\mathrm{FromMFile}\left(\mathrm{mfile},'\mathrm{string}'\right)$
 ${"r1 := proc\left( a, b \right) local r; # file r1.m ?FromMfile function reference example 1/2 r := r2\left(a\right) . r3\left(b\right); return r; end proc; r2 := proc\left( a \right) local r; # file r2.m ?FromMfile function reference example 2/2 r := 2 . a; return r; end proc;"}$ (2)
 > $\mathrm{mplfile}≔\mathrm{FileTools}:-\mathrm{TemporaryFile}\left("r1",".mpl"\right)$
 ${\mathrm{mplfile}}{≔}{"/tmp/mpldoc2/r1yYoYxV9R.mpl"}$ (3)
 > $\mathrm{FromMFile}\left(\mathrm{mfile},\mathrm{mplfile}\right)$
 > $\mathrm{mwfile}≔\mathrm{FileTools}:-\mathrm{TemporaryFile}\left("r1",".mw"\right)$
 ${\mathrm{mwfile}}{≔}{"/tmp/mpldoc2/r1bx70dpPu.mw"}$ (4)
 > $\mathrm{FromMFile}\left(\mathrm{mfile},\mathrm{mwfile}\right)$
 > $\mathrm{FromMFile}\left(\mathrm{mfile},'\mathrm{path}'=\left[\right]\right)$
 Evaluating: r1 := proc( a, b )     local r;     # file r1.m ?FromMfile function reference example 1/2     r := r2(a) . r3(b);         return r; end proc;
 ${\mathbf{proc}}\left({a}{,}{b}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{r}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{r}{≔}{\mathrm{.}}{}\left({\mathrm{r2}}{}\left({a}\right){,}{\mathrm{r3}}{}\left({b}\right)\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{r}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (5)
 > $\mathrm{r1}\left(10,2\right)$
 ${\mathrm{r2}}{}\left({10}\right){}{\mathrm{r3}}{}\left({2}\right)$ (6)