Call Matlab script via command line

조회 수: 20 (최근 30일)
N/A
N/A 2019년 9월 10일
답변: Lexi Crommett 2021년 4월 9일
We try to call a Matlab script via MS-DOS command line:
"D:\Install_Matlab\bin\matlab.exe" -nodisplay -nodesktop -r "run('D:\test.m');exit;"
We added some extra options (like -nodesktop) in the command because we want to run this command in batch (so without any user interaction). With the above command we can successfully run our script ("test.m"). However, the problem is that we don't get any error message if the script fails. What do we have to change in our command so that we can retrieve the error(s)?
  댓글 수: 3
N/A
N/A 2019년 9월 10일
Ok, so if you return an error in the Matlab script (or there is a technical error, for example a syntax error) the command will not automatically give a returncode different from 0?
(with compiled Matlab code we just check the RC of the MS-DOS command)
Rik
Rik 2019년 9월 10일
I would strongly suggest you make sure the code can run in the first place, before running it headless. Then you can wrap the whole thing in a try-catch and write any error to a text file. The return code might be set with your current setup, but I have very little experience with this level of detail in running Matlab headless, so I don't know what settings are available.

댓글을 달려면 로그인하십시오.

답변 (1개)

Lexi Crommett
Lexi Crommett 2021년 4월 9일
You can use the -logfile "logfilename" startup option to write any output from MATLAB to a log file. This should allow you to see any errors by looking at that log file.
Your command would then look like this:
"D:\Install_Matlab\bin\matlab.exe" -nodisplay -nodesktop -logfile "D:\myLog.txt" -r "run('D:\test.m');exit;" (assuming that D is the directory where you want the log file)

카테고리

Help CenterFile Exchange에서 C Shared Library Integration에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by