0

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!

1

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.