不知道为何写这篇日志,或许以后也很少在linux下用到MATLAB,更不会用到这个perl和matlab的这些接口
,反正稀里糊涂的安装好了,就把过程简单的记录一下
CPAN上下载Math-Matlab的安装文件http://search.cpan.org/~zman/Math-Matlab-0.08/
Math-Matlab-0.08的INSTALL文件
第1步就说:Install a mod_perl enabled web server (http://perl.apache.org/).好吧,先安装mod_perl:
mod_perl安装:
下载mpd_perl 2.0 http://perl.apache.org/download/index.html
mod_perl-2.0.4文件夹中的INSTALL文件中的安装方法是:
% perl Makefile.PL MP_APXS=/usr/local/apache2/bin/apxs
% make && make test
% make install
可是,我的CentOS 5.4系统中,找不到apxs。如下解决:
[root@zhuliting matlab]# yum search apxs
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* updates: mirrors.163.com
* addons: mirrors.163.com
* extras: mirrors.163.com
=========================================== Matched: apxs ============================================
httpd-devel.i386 : Development tools for the Apache HTTP server.
[root@zhuliting matlab]# yum install httpd-devel
...
...
[root@zhuliting matlab]# find / -name apxs
/usr/sbin/apxs
这个是apxs的路径,下面会用到。
[root@zhuliting mod_perl-2.0.4]# perl Makefile.PL MP_APXS=/usr/sbin/apxs
[root@zhuliting mod_perl-2.0.4]#/usr/sbin/apxs -q LIBEXECDIR
会显示modelus的路径:
/usr/lib/httpd/modules
追加httpd.conf:[这里可以不用追加了,修改httpd.conf,http服务将不能开启了!]
LoadModule perl_module /usr/lib/httpd/modules/mod_perl.so
最后
[root@zhuliting mod_perl-2.0.4]# make && make install
到这里,mod_perl安装完成,我们回到Math_Matlab-0.08的安装……
[root@zhuliting Math-Matlab-0.08]# perl Makefile.PL MP_APXS=/usr/sbin/apxs
Enter command to execute Matlab [ /usr/local/bin/matlab -nodisplay -nojvm ] :
这里不能直接敲回车,我用find 命令,发现MATLAB命令在/usr/local/Matlab/bin/matlab,所以,我手动输入:/usr/local/Matlab/bin/matlab -nodisplay -nojvm
回车后,提示信息如下:
Attempting to run Matlab ... which: no shopt in (/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin)
OK
Checking if your kit is complete...
Looks good
'MP_APXS' is not a known MakeMaker parameter name.
Writing Makefile for Math-Matlab
Most of the tests for the Server and Remote classes of the the
Math::Matlab package are not run by default.
In order to test them, you will need to set up a server according to the
instructions in the INSTALL file, then edit the 'server.config' file
with the appropriate values and re-run 'make test'.
执行Math-Matlab-0.08的INSTALL文件第2步
[root@zhuliting Math-Matlab-0.08]# make install
第3步到第5步,没怎么看明白,呵呵
如果你不是很明白要做什么,就什么也不要做了,目前为止,在本地电脑上Math-Matlab已经可以用 了。
写了个测试程序,居然成功了……就这样吧
附perl测试程序:
#!/usr/bin/perl
use Math::Matlab::Local;
$matlab = Math::Matlab::Local->new({
cmd => '/usr/local/Matlab/bin/matlab -nodisplay -nojvm',
root_mwd => '/etc/httpd/matlab-server'
});
#my $code = q/fprintf( 'Hello world!/n' );/;
my $code = q/disp(pinv([1 2;3 4;5 6;]));/;
if ( $matlab->execute($code) ) {
print $matlab->fetch_result;
} else {
print $matlab->err_msg;
}
另:
#$matlab->execute($code,"/etc/httpd/matlab-server","zlt.m") 可以执行指定目录下的m文件
如:
#!/usr/bin/perl
use Math::Matlab::Local;
$matlab = Math::Matlab::Local->new({
cmd => '/usr/local/Matlab2009a/bin/matlab -nodisplay -nojvm',
root_mwd => '/etc/httpd/matlab-server'
});
my $code='';
if ( $matlab->execute($code,"/etc/httpd/matlab-server","zlt.m") ) {
print $matlab->fetch_result;
} else {
print $matlab->err_msg;
}