全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
4431 2
2008-04-29

Connecting MATLAB to R

http://www.mathworks.com/matlabcentral/files/5051/content/Rdemo.html

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=5051&objectType=file#

209191.zip
大小:(127.41 KB)

 马上下载

本附件包括:

  • Rdemo.m
  • Contents.m
  • evalR.m
  • getRdata.m
  • openR.m
  • putRdata.m
  • closeR.m
  • Rdemo_01.png
  • Rdemo_02.png
  • Rdemo_03.png
  • Rdemo_04.png
  • Rdemo.png
  • Rdemo.html


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2009-3-18 21:22:00

Connecting MATLAB to R

The statistical programming language R has a COM interface. We can use this to execute R commands from within MATLAB. The connection requires a local installation of R and also of the R-(D)COM Interface (for Windows only). This can be downloaded from http://lib.stat.cmu.edu/R/CRAN/other-software.html or other CRAN mirror site.

Contents

Connect to an R Session

[status,msg] = openR; if status ~= 1 disp(['Problem connecting to R: ' msg]); end 

Run one of the R demos to test the connection.

evalR('demo("persp")'); 

Now copy the volcano data into MATLAB

volcano = getRdata('volcano'); 

Use SURF to plot the volcano

surf(volcano); axis off; view(-135,40); 

You can also copy the colormap from R

cols = char(evalR('terrain.colors(20)')); red = hex2dec(cols(:,[2 3])); green = hex2dec(cols(:,[4 5])); blue = hex2dec(cols(:,[6 7])); colormap([red,green,blue]/256); 

Another view

The R variable z has edges filled in for more realistic viewing. The surface is flipped around in the R version.

z = getRdata('z'); h = surf(fliplr(z)); axis off; view(-135,40); 

Add some lighting and turn off the edges

lightangle(-135,40); lighting gouraud set(h,'linestyle','none'); 

Now do some arithmetic in R. First push some data into R.

a = 1:10; putRdata('a',a) 

Run a simple R command

b = evalR('a^2') 
b = 1 4 9 16 25 36 49 64 81 100 

Run a series of commands and grab the result

evalR('b <- a^2'); evalR('c <- b + 1'); c = getRdata('c') 
c = 2 5 10 17 26 37 50 65 82 101 

Close the connection

closeR 
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-5-29 14:48:24
很好的东西江,
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群