简体   繁体   中英

php call matlab

I am using php to build a website that can calculate some convex programming. However, when I tried to connect php and matlab, I can execute matlab and some of its command, but I cannot run any matlab functions.

I am using SSH, Windows 7, Matlab R2012a. The following are some of my observation:

  1. I cannot execute any matlab function(function in .m file) via php, but I can run simple command such as cd, 3*3 by matlab via our php code. I also try to run matlab in UNIX using SSH. I can successfully run both matlab function and command. One more thing is that when I cd in php calling matlab, it shows a directory (/misc/uac_std/fyp/y13/fyp_dt/public_html/) which is different from the normal directory (/uac/std/fyp/y13/fyp_dt/public_html)

  2. In php, every time I run matlab, I have this warning message - Check directory permissions.Warning: failed to create prefere nce directory /root/.matlab/R2012a. I have searched in google for it and try to make directory manually to create .matlab/R2012a in the home directory (cd~), but it did not help.

  3. When running matlab in both SSH and php, I found that we run different version of matlab. When I run it in SSH, the version is R2009a. When php, the version is R2012a. I do not know whether it is related to our problem or not, but it's just strange. And also, the matlab I use in my college is R2011b...

Here is my php code:

if(isset($_POST['filepath'])) {

$filename  = $_POST['filepath'];
    $command="/usr/local/bin/matlab -nodisplay -nosplash -r \"test()\"";
    $output=shell_exec($command); 
    print "$output\n";  
}

Can someone help me?

You could create an input file for Matlab. Basically the same technique as http://www.danpearce.co.uk/php_and_matlab , but use PHP to write the input file and then parse the output file from Matlab.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM