Matlab system call

If I want to call the script "filtermapq.sh" inside the matlab script. How can I call and then wait for the script to complete before resuming the rest of the matlab code? I am not the best with Matlab.

I am currently using this command:

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

However, I don't think matlab code is waiting for this to complete before continuing.


Answer:

Hey guys, I realized that the problem is in my line of code. The problem was that Matlab did not interpret the spaces between the variables that I entered, and instead scribbled them all together on one big line. Where my script takes 3 variables. I hope this helps anyone in the future, the correct code is as follows:

 system(['./util/filtermapq.sh ' var1 ' ' var2 ' ' var3]) 
+6
source share
4 answers

Answer

Hey guys, I realized that the problem is in my line of code. The problem was that Matlab did not interpret the spaces between the variables that I entered, and instead scribbled them all together on one big line. Where my script takes 3 variables. I hope this helps anyone in the future, the correct code is as follows:

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

I see that you have found a solution, let me give you a little more elegant, which will make life easier in the future.

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

It can also be conveyed in numbers, for example, or in other interesting materials. In addition, you can do this to help debug such issues.

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

This will display the exact command you are trying to run. If your system command does not work, copy it to the command prompt window and see if it works there. If he doesnโ€™t figure out how to massage the text to make it work, and correct your code accordingly.

+2
source

Good introduction: http://blogs.mathworks.com/desktop/2010/05/17/calling-shell-commands-from-matlab/


Edit : Quote from the link.

"By default, [system] pauses MATLAB until the system command is turned off.

+1
source

One way is to create a script to create a temporary file when it starts, and then delete that file at the end. Inside Matlab, you simply run a do... while check for this file. Once the file is deleted, you know that the process is complete.

+1
source

Source: https://habr.com/ru/post/911325/


All Articles