Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab system call

Tags:

bash

matlab

If I want to call a script "filtermapq.sh" inside a matlab script. How would I go about calling it and then waiting for the script to finish before resuming the rest of the matlab code? I am not the best with matlab.

Currently I am using this command:

system(['./util/filtermapq.sh ' var1 var2 var3])

However, I don't think that the matlab code waits for this to finish before continuing.

like image 636
E.Cross Avatar asked Mar 21 '12 16:03

E.Cross


People also ask

How does MATLAB system () work?

The function starts a new cmd/shell process, executes command , exits the process, and returns to the MATLAB® process. Updates to the system environment made by command are not visible to MATLAB. [ status , cmdout ] = system( command ) also returns the output of the command to cmdout .

Can MATLAB Run command line?

You can execute operating system commands from the MATLAB® command line using the ! operator or the system function.

Which shell is MATLAB using?

Otherwise, MATLAB uses the Bourne shell.

How do I run a command in MATLAB?

Go to the Editor tab and click Run . MATLAB® displays the list of commands available for running the function. Click the last item in the list and replace the text type code to run with a call to the function including the required input arguments.


1 Answers

I see that you found a solution, let me give you a bit more elegant one, which will make life easier for the future.

system(sprintf('./util/filtermapq.sh %s %s %s', var1, var2, var3))

This could also pass in numbers, for instance, or other cool stuff. Also, you could do this to help with debugging such issues.

command=sprintf('./util/filtermapq.sh %s %s %s',var1, var2, var3);
fprintf('%s\n',command);
system(command);

That will log out to the screen the exact command that you are attempting to run. If your system command doesn't work, copy/paste it into a command line window, see if it works there. If it doesn't figure out how to massage the text to make it work, and fix your code appropriately.

like image 89
PearsonArtPhoto Avatar answered Sep 27 '22 17:09

PearsonArtPhoto