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.
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 .
You can execute operating system commands from the MATLAB® command line using the ! operator or the system function.
Otherwise, MATLAB uses the Bourne shell.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With