• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

karpathy/MatlabWrapper: C++ convenience class to communicate with a Matlab insta ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

karpathy/MatlabWrapper

开源软件地址(OpenSource Url):

https://github.com/karpathy/MatlabWrapper

开源编程语言(OpenSource Language):

C++ 100.0%

开源软件介绍(OpenSource Introduction):

MatlabWrapper

Andrej Karpathy 27 August 2012

This C++ library is a convenience wrapper around Matlab Engine, especially if you use Eigen matrix library for working with matrices. It should be quite easy to adapt it to other library types as well.

Usage

Consider the simplest example: You have an Eigen::MatrixXf X; lying around and you'd love to run k-means on its rows. But naturally, you don't feel like re-implementing k-means for Eigen matrices from scratch! So you write:

  
  MatlabWrapper mw;
  mw.sendMat("X", X); // transfer it over to the engine under name "X"
  mw.exec("[IDX, C] = kmeans(X, 10);");
  Eigen::MatrixXf mat;
  mw.receiveMat("C", mat);
  
  // done!

That felt good. Now supose you've computing something complicated and would really like to explore it a bit interactively-- do a few plots, run some statistics, etc. No problem:

  MatlabWrapper mw;
  mw.sendMat("X", X);
  mw.interact();

This will start an interactive session with matlab right in your shell! You get to type whatever you wish:

>> plot(X(:,1), X(:,2)); // interesting!
>> close;
>> hist(X); 
>> close;

Entering qq will resume the c++ program right where it left off. This is quite great for debugging as well.

Install

Eigen library is a dependency, and so is Matlab, naturally. If you don't have eigen, install it with

$ sudo apt-get install libeigen3-dev

Also make sure you have tcsh, which is require for matlab engine to work

sudo apt-get install tcsh

At this point you may want to get the official MATLAB demo to run (see below)

then to install this library.

$ git clone [email protected]:karpathy/MatlabWrapper.git 
$ cd MatlabWrapper
$ mkdir build 
$ cd build
$ cmake ..
$ make
$ ./test1

where last line runs a small demo. Naturally, the above will probably not run right away because these things never do. Have a look inside CMakeLists.txt and modify the include/library paths according to your system preferences. I tried to document it as best I could.

Getting Matlab Engine to run

If you haven't used Matlab Engine yet, try to get their demo running first. Here is the main documentation: http://www.mathworks.com/help/techdoc/matlab_external/f29148.html

In particular of interest is this link on getting their engdemo.c running: http://www.mathworks.com/help/techdoc/matlab_external/bsq776w-1.html#bsq78dr-9

If you can get that running, you're halfway there! Problems I ran across:

  • You must have tcsh installed! sudo apt-get install tcsh
  • I needed to add a missing .so file to my $LD_LIBRARY_PATH in .bashrc and source it.
  • They were looking for libc.so.6 in /lib64/ but mine was in /lib/x86_64-linux-gnu/ so I had to symlink it over.

Good luck!

License

BSD




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap