brian-lau / MatlabR

Call R from Matlab

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MatlabR

Connect Matlab to R using Rserve, a TCP/IP server that allows other programs to use facilities of R. A generic class (MatR) connects to RServe through its Java client, which renders the interface platform independent. This contrasts with other solutions which are Windows-only.

Installation

Add parent directory to your Matlab path, then run setupMatR in Matlab.

Usage

On the machine running R (server):

library(Rserve)
run.Rserve()
-- running Rserve in this R session (pid=1234), 1 server(s) --
(This session will block until Rserve is shut down)

On the machine running Matlab (client):

r = MatR();
R version 3.3.3 (2017-03-06)

Evaluating simple commands:

r.eval('seq(1,10)');
r.result.asDoubles()

ans =
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10

Assign variables to R workspace:

r.assign('x',1:5)
r.assign('y',0.5)
r.eval('x*y').result.asDoubles()

ans =

    0.5000
    1.0000
    1.5000
    2.0000
    2.5000

Contributions

MatlabR Copyright (c) 2017 Brian Lau brian.lau@upmc.fr, BSD-2

Rserve Copyright (c) Simon Urbanek, GPL-2

Please feel free to fork and contribute!

About

Call R from Matlab

License:BSD 2-Clause "Simplified" License


Languages

Language:MATLAB 87.2%Language:R 12.8%