不知道為何寫這篇日誌,或許以後也很少在linux下用到MATLAB,更不會用到這個perl和matlab的這些介面
,反正稀裡糊塗的安裝好了,就把過程簡單的記錄一下
關於MATLAB的安裝,請參考師姐的部落格:http://blog.sina.com.cn/s/blog_5f0fbdee0100mfkq.html
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;
}