matlab停止运行命令,如何在命令行脚本完成之后停止返回MATLAB?

I see in the MATLAB help (matlab -h) that I can use the -r flag to specify an m-file to run. I notice when I do this, MATLAB seems to start the script, but immediately return. The script processes fine, but the main app has already returned.

Is there any way to get MATLAB to only return once the command is finished? If you're calling it from a separate program it seems like it's easier to wait on the process than to use a file or sockets to confirm completion.

To illustrate, here's a sample function waitHello.m:

function waitHello

disp('Waiting...');

pause(3); %pauses 3 seconds

disp('Hello World');

quit;

And I try to run this using:

matlab -nosplash -nodesktop -r waitHello

解决方案

Quick answer:

matlab -wait -nosplash -nodesktop -r waitHello

In Matlab 7.1 (the version I have) there is an undocumented command line option -wait in matlab.bat. If it doesn't work for your version, you could probably add it in. Here's what I found. The command at the bottom that finally launches matlab is (line 153):

start "MATLAB" %START_WAIT% "%MATLAB_BIN_DIR%\%MATLAB_ARCH%\matlab" %MATLAB_ARGS%

The relevant syntax of the start command (see "help start" in cmd.exe) in this case is:

start ["window title"] [/wait] myprogram.exe args ...

A bit higher, among all of the documented command line options, I found (line 60):

) else if (%opt%) == (-wait) (

set START_WAIT=/wait

) else (

So specifying -wait should do what you want, as long as you're also exiting matlab from your script (otherwise it will wait for you to terminate it interactively).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值