当前位置: 动力学知识库 > 问答 > 编程问答 >

bash - run Matlab commands one by one on windows using .bat file

问题描述:

I am trying to run a function on different files; I would like to use Bash-Like script to do that. When I looked on the web; I found that I can use .bat file.

My .bat file contains this

matlab -bodesktop -nosplash -r myFunction('input_1.txt')

matlab -bodesktop -nosplash -r myFunction('input_2.txt')

matlab -bodesktop -nosplash -r myFunction('input_3.txt')

matlab -bodesktop -nosplash -r myFunction('input_4.txt')

matlab -bodesktop -nosplash -r myFunction('input_5.txt')

When I double click the file, it seems that these commands are running on parallel, which, makes the PC to crash.

I looked on Matlab Forum for alternative solutions, but couldn't work with me

Another option I found:

start -wait matlab -bodesktop -nosplash -r "myFunction('input_1.txt');exit"

..

Anyone used this before ?

网友答案:

There are two matlab binaries, one matlabroot/bin the other in matlabroot/bin/win64/. The first one is only a launcher application which typically terminates as soon as the main application is started successfully. To keep it open until the main application terminates you have to use the -wait option with your matlab.exe (not to be confused with the start -wait option, bot can be used together).

In your case try:

matlab -wait -nodesktop -nosplash -r myFunction('input_1.txt')

(I assume you intended to use "nodesktop").

All start parameters for windows are explained here in the documentation. (You have to click "option1...optionN" to expand the relevant section.)

网友答案:

First check that you have the option spelled correctly. Click here for the options.

Try this:

matlab -wait -nodesktop -nosplash -r "myFunction('input_1.txt')"

Edit:

By default, when you call the matlab command from a script, the command starts MATLAB and then immediately executes the next statements in the script. The -wait option pauses the script until MATLAB terminates.

Use the -wait option in a startup script to process the results from MATLAB. Calling MATLAB with this option blocks the script from continuing until the results are generated.

分享给朋友:
您可能感兴趣的文章:
随机阅读: