Matlab script - running an external command (nonblocking)
From a script in Matlab, I need to run an extern开发者_运维问答al command. Normally this is done with system, but script execution blocks until the command completes. Is there a way to execute a command from a script without blocking execution?
EDIT: OS is Windows Server.
On windows you need to use start
system('start notepad.exe');
This may be overkill, but if you have the full install of matlab, you can use the Parallel Computing toolbox to run the command in a separate thread. It's actually pretty easy to do, the basic syntax would be:
obj = createJob();
set( obj, 'FileDependencies', {<list .m files used here>, 'ExampleFileFunc.m'});
task = createTask(obj, @ExampleFileFunc, 1, {4});
submit(obj);
waitForState(task,'finished');
varargout = get(task,'OutputArguments');
The {4}
is the number of outputs from ExampleFileFunc
.
You can use bang (!) and then the command, for instance
!vi
And to let it run without blocking execution it would be
!vi &
The program will show up on a separate screen and you get back to the Command Window so you can continue running MATLAB language statements. It does the same thing for an script so I guess this is what you want to use.
精彩评论