


% Connecting MATLAB to R The statistical programming language R has a COM interface. We can use this to execute R commands from within MATLAB.


0001 %% Connecting MATLAB to R 0002 % The statistical programming language R has a COM interface. We can use 0003 % this to execute R commands from within MATLAB. 0004 0005 %% Connect to an R Session 0006 openR 0007 0008 %% Push data into R 0009 a = 1:10; 0010 putRdata('a',a) 0011 0012 %% Run a simple R command 0013 b = evalR('a^2'); 0014 0015 %% Run a series of commands and grab the result 0016 evalR('b <- a^2'); 0017 evalR('c <- b + 1'); 0018 c = getRdata('c'); 0019 0020 %% Close the connection 0021 closeR