Wants to execute matlab file with php
古いコメントを表示
how to pass php dynamic file path to matlab(any function where I can execute matlab file code). Want to show the output on browser. SO, how can I code for this.
採用された回答
その他の回答 (5 件)
Arijit Nandi
2018 年 2 月 18 日
0 投票
$cmd = 'C:\MATLAB\R2017b\bin\matlab -automation -sd ' . $pwd . ' -r "magicSquare(5);exit" -wait -logfile log.txt';
please explain this Kojiro Saito . I am new in matlab.
4 件のコメント
Kojiro Saito
2018 年 2 月 19 日
編集済み: Kojiro Saito
2018 年 2 月 19 日
The above command is applicable in Windows.
-automation
This option makes MATLAB not display the splash screen and makes minimizes the window.
-sd ' . $pwd . '
This option makes MATLAB's startup folder to current directory in PHP.
-r "magicSquare(5);exit"
This options makes MATLAB run magicSquare(5) and exit.
-wait
This option pauses the script until MATLAB terminates.
-logifle log.txt
This options makes MATLAB output a log file into log.txt.
NOTE: Options of matlab terminal command are different in OS. For reference, please see these documents.
Arijit Nandi
2018 年 2 月 21 日
編集済み: Arijit Nandi
2018 年 2 月 21 日
Thank you sir. It worked but it is taking more time . Is there any process to speed up this computation . I've made a stand alone program in Matlab , and want to call that for the calculation . Can I do this without installed in the local server machine.
Kojiro Saito
2018 年 2 月 21 日
Do you mean you have created a stand alone application by compiling with MATLAB Compiler? If so, you would have created magicSquare.exe. Put this exe in PHP current directory, and change the command line description to .
$cmd = 'magicSquare.exe 5';
in PHP script.
Walter Roberson
2018 年 10 月 24 日
Note that using MATLAB Compiler does not speed up execution. The exe produced use the same execution engine as interactive MATLAB does.
MATLAB Coder (a different product) generates C/C++ code that can potentially be faster, if you are using the subset of MATLAB that it supports (and in some highly vectorized cases, MATLAB itself is more efficient than the generated C/C++ code, which might not be using the high performance libraries.)
If you need the full support of MATLAB Compiler but need the startup time to be reduced then the appropriate product is MATLAB Production Server.
Samreen Akhtar
2018 年 4 月 5 日
0 投票
C:\MATLAB\R2017b\bin\matlab
Samreen Akhtar
2018 年 4 月 5 日
0 投票
what does it mean
4 件のコメント
Kojiro Saito
2018 年 4 月 5 日
It means $MATLAB_INSTALL\bin\matlab.exe where $MATLAB_INSTALL is installation folder. In the below sample php, MATLAB is supposed to be installed in C:\MATLAB\R2017b.
If MATLAB is installed in C:\Program Files\MATLAB\R2017b, the "C:\MATLAB\R2017b\bin\matlab" of $cmd in the above sample.php should be replaced with C:\Program Files\MATLAB\R2017b\bin\matlab.
Samreen Akhtar
2018 年 4 月 6 日
I want to execute php and want to show the image produced by matlab but it does not show any output...Can you please check that what is going wrong.
Kojiro Saito
2018 年 4 月 10 日
You need to pass the output image to php and php needs to create img tag. Simple way is as follows.
showDise.m
function showDise( )
fig = figure('visible', 'off');
a=imread('dise.jpg');
imshow(a);
h=imdistline();
api = iptgetapi(h);
saveas(fig, 'result.jpg')
end
sample.php
<!DOCTYPE html>
<html>
<head>
<title>PHP Test</title>
<meta charset="utf-8">
</head>
<body>
<?php
$pwd = getcwd();
$cmd = 'C:\MATLAB\R2017b\bin\matlab.exe -automation -sd ' . $pwd . ' -r "showDise;exit" -wait -logfile log.txt';
exec($cmd, $output, $retval);
if ($retval == 0){
// Read from image file which MATLAB has created and return img tag
echo '<img src="result.jpg"/>';
} else {
// When command failed
echo '<p>Failed</p>';
}
?>
</body>
</html>
Please replace "C:\MATLAB\R2017b\bin\matlab.exe" in $cmd with your MATLAB installation path.
Nazia Hameed
2018 年 10 月 24 日
did u manage to call matlab using php ?
Fatima Kahoot
2018 年 4 月 25 日
0 投票
i have created an exe file of matlab standalone application and wants to execute it with php using exec command and wants to show the output that is created by matlab .exe file in web where user will interactively change the distance of imdistline and then save the distance retrieved using api.getdistance in database. i am new in matlab and does not know how it can be done. Please help me in this regard and please tell me that where is to place Matlab Compiler Runtime? i have also attached my code of php and matlab.
1 件のコメント
Kojiro Saito
2018 年 4 月 26 日
I'm not sure what is needed for input and what output would be from ObjectSizeCalculator.exe.
If the output is csv or text file, for example, result.csv, the PHP codes might be similar to the following.
$lines = file('result.csv');
echo '<p>Results:<br>';
foreach($lines as $line)
{
echo $line.'<br>';
}
echo '</p>';
Also, MATLAB Runtime should be installed in the server where PHP is running.
Mario Jose
2018 年 8 月 16 日
Hi, I'm new to matlab and I'd like to know if someone helps me. I want to run a matlab file, but you have to pass a route, I think it can be the concatenation, the route receives it by parameter the file of mattab
<!DOCTYPE html>
<html>
<head>
<title>PHP Test</title>
<meta charset="utf-8">
</head>
<body>
<?php
$pwd = getcwd ();
$ruta='D:\Tesis2.0\images\CPT-792_2.jpg';
$cmd = 'C:\Program Files\MATLAB\R2017a\bin\matlab.exe -automation -sd ' . $pwd . ' -r "D:\Tesis2.0\prueba2('$ruta');quit" -wait -logfile log.txt';
exec($cmd, $output, $retval);
if ($retval == 0){
$c = file_get_contents('D:\Tesis2.0\placa.txt');
echo $c;
} else {
// When command failed
echo '<p>Failed</p>';
}
?>
</body>
</html>
カテゴリ
ヘルプ センター および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
