Reputation: 1151
I feel like i am almost there but need the extra push! I am trying to call a MATLAB script from Python (I'm not worried about the output of the MATLAB script - it runs independently). However, i must be able to send an input into the MATLAB script from python.
Right now I have(in python):
myvartoinput = 55
cmd = 'myscript.m'
process = Popen(["matlab", "-nosplash", "-nodesktop", "-r", cmd], shell=True)
process.communicate()
# Also, how do i 'exit' the MATLAB so it doesn't continue to run
I am not sure how to add "myvartoinput" into the 'myscript.m' file. Also, did I call the script correctly? Finally, i would like it to "exit" so it doesn't stay open in the background on my pc. Any help would be appreciated!
Upvotes: 0
Views: 560
Reputation: 13
I have solved it differently:
import os
import subprocess
myvartoinput = 55
subprocess.call(['matlab', '-wait','-nosplash','-nodesktop','-r','myscript(\'%s\')' %(myvartoinput )])
Arguments:
'-wait' - python waits till Matlab executes script and continues;
'-nodesktop' - only matlab command window is called;
'-nosplash' - suppresses the display of the splash screen;
'-r' - argument after which follows name of a script
More info here: http://se.mathworks.com/help/matlab/matlab_env/startup-options.html
Upvotes: 1