我正在开发一个需要通过php运行matlab脚本的项目..我已经搜索了很多解决方案,但没有得到任何解决方案..有代码示例..在命令行上工作正常但不通过网页浏览器
php code
<?php
if(isset($_POST['filepath'])) {
$filename = "test1.txt";
$inputDir = "G:\soft";
$outputDir1 = "C:\output".$filename;
$command = "matlab -sd ".$inputDir." -r\
phpcreatefile('".$outputDir1."\\".$filename."')";
exec($command);
echo "The following command was run: ".$command."<br/>";
echo $filename." was created in ".$outputDir1."<br/>";
}
?>
function phpcreatefile(filepath)
% Open the file
%filepath='c:\text1.txt';
fid = fopen(filepath, 'wt');
for i = 1:100
% Create random number
randNumber = [num2str(rand(1)) '\n'];
% Write number to file
fprintf(fid, randNumber);
end
% Close file
fclose(fid);
% Quit MATLAB
quit force