MATLAB输出到PHP代码 [英] MATLAB output to PHP code

查看:217
本文介绍了MATLAB输出到PHP代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将MATLAB输出传递给我的php代码.

I want to pass MATLAB output to my php code.

我的MATLAB代码,我有:

My MATLAB code, I have:

function x = returnX()
    x = 100;
end


还有我的PHP代码:


And my PHP code:

<?php
     $command = "matlab -nojvm -nodesktop -nodisplay -r \"x = returnX();\"";
     passthru($command, $output);
     echo($output)
?>

但是,它打印0,而不是100.
当我在cmd中键入命令时,它显示为100.但是,当我通过PHP代码尝试该命令时,它将不起作用.谁能帮我如何将MATLAB的输出值设置为php变量?谢谢!

However, this prints 0, not 100.
When I type the command in my cmd, it shows 100. But when I try it through PHP code, it does not work. Can anyone help me how to set the output value of MATLAB to php variable? Thanks!

推荐答案

您应该使用exec来返回标准输出,而不要使用像passthru这样的退出代码.

You should rather use exec, which return the standard output, rather than the exit code like passthru.

在matlab代码中显示输出:

display the output in the matlab code:

function x = returnX()
    x = 100;
    display(x);
end

在php代码中使用exec:

<?php
     $command = "matlab -nojvm -nodesktop -nodisplay -r \"x = returnX();\"";
     $output=exec($command);
     echo($output)
?>

这篇关于MATLAB输出到PHP代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆