Php call matlab

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

I am using SSH, Windows 7, Matlab R2012a. Here are some of my observations:

  • I cannot execute any matlab function (function in .m file) through php, but I can run a simple command like cd, 3 * 3 through matlab through our php code. I am also trying to run matlab on UNIX using SSH. I can run both the matlab function and the command successfully. One more thing: when I cd in php calls 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)

  • In php, every time I run matlab I have this warning message - Check directory permissions. Warning: Failed to create preferred directory /root/.matlab/R2012a. I have googled for this and will try to make a directory manually to create .matlab / R2012a in the home directory (cd ~) but that didn't help.

  • When running matlab in SSH and php, I found that we are running a different version of matlab. When I run it in SSH, version R2009a. When php, version R2012a. I don't know if this is related to our problem or not, but it's just weird. And also, the Matlab I use in my college is R2011b ...

Here's 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 anyone help me?

+3


source to share


1 answer


You can create an input file for Matlab. Basically the same method 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.



0


source







All Articles