[R] Matlab to R ?

Paul Gilbert pgilbert at bank-banque-canada.ca
Thu Oct 3 16:07:27 CEST 2002


Michel ARNAUD wrote:
> 
> Hello
> 
> I have a matlab program. I would like to transfer code in R. Is there any translator ?

Below is an old Unix script which does about 80% of the simple part of
translation. You will need to work out the harder things (like many of
the function calls). You do need to know pretty well what your matlab
code does, and know enough R to translate the hard parts. It would also
be a good idea to have some examples to test with.

Paul Gilbert
______
#!/bin/csh
cp $1 $2
ex -s $2 <<eof
   g/%/s//#/g
   g/function\(..*\)=\(..*\)(\(..*\)/s//\2 <-function( \3 { \1/
   g/end/s//   } #/
   g/for\(..*\)=\(..*\):\(..*\)/s//for ( \1 in \2 : \3 ) {/
   g/_/s//./g
   g/;/s///g
   g/==/s//@@/g
   g/=/s//<-/g
   g/@@/s//==/g
   g/zeros(/s//matrix(0,/g
   g/ones(/s//matrix(1,/g
   g/eye(/s//diag(1,/g
   g/\/s//solve(,)/g
   g/fsolve('\(..*\)'/s//ms(~\1 /g
   g/param(\(..*\))/s//param[ \1 ] /g
   g/var(\(..*\))/s//var[ \1 ] /g
   g/mod1(\(..*\)/s//mod1[ \1 /g
   wq
eof
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list