声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

声振论坛 展示 基础理论 查看内容

使用php在网页执行matlab

2012-10-18 06:57| 发布者: aspen| 查看: 14290| 评论: 0|原作者: Jillian|来自: 振动论坛

摘要: 目录 IncludingStartup Options in a Shortcut on Windows Systems SpecifyingStartup Options in the MATLAB Startup File CommonlyUsed Startup Options PassingPerl Variables on Startup Startupand Callin ...
通过php调用linux命令,可以实现远程调用matlab.
试验环境:Fedora16, matlab2012b linux version, Google chrome 18.0.1025.108 beta
以下代码实现了在网页输入matlab命令并显示执行结果。注意:如果不加-nodisplay选项,会出现" no display specified"的警告,当然可以在执行matlab命令之前unset DISPLAY也可以直接在terminal执行matlab。
如果你仅仅想远程调用matlab函数,可以参考mathworks的php webservice相关文档,此处也可以参考官方关于python调用的文档。
以下代码对于plot()等绘图命令会出现{Warning: Objects of graph2d.lineseries class exist - not clearing this class or any of its super-classes}错误,目前未解决(也就是无法绘图)。但是通过ssh远程登陆服务器调用相同命令可以plot并save图像,不解。

[php] view plaincopyprint?
  1.   
  2.       
  3.         
      
  4.             输入命令:   
  5.                   
      
  6.         
  7.   
  8.       
  9.   
  10.   
  11. phpinfo();  
  12. if(isset($_POST['cmd']))  
  13. {  
  14. $cmd = $_POST['cmd'];  
  15. $command="/usr/local/MATLAB/R2012a/bin/matlab -nodisplay -nosplash -r "."\"".$cmd."\"";  
  16. //echo $command."
    ";  
  17. //$command="/usr/local/MATLAB/R2012a/bin/matlab -r "."\"".$cmd."\"";  
  18. shell_exec("unset DISPLAY");//删除DISPLAY环境变量  
  19. $out = shell_exec($command);  
  20. $str="< M A T L A B (R) >  
  21.                   Copyright 1984-2012 The MathWorks, Inc.  
  22.                     R2012a (7.14.0.739) 32-bit (glnx86)  
  23.                               February 9, 2012  
  24.   
  25.    
  26. To get started, type one of these: helpwin, helpdesk, or demo.  
  27. For product information, visit www.mathworks.com.";  
  28. $out=ltrim($out,$str);  
  29. $out=rtrim($out,"  
  30. >>");  
  31. echo $out;  
  32. }  
  33. ?>  
复制代码

本文内容由 Jillian 提供

最新评论

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-4-26 17:28 , Processed in 0.065375 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部