0

I am working on a machine learning program and attempting to perform experiments on the variables of my neural network. Due to Matlab's prowess with matrices, the learning is being performed in Matlab but for ease of use, the use of the learned outputs is in Python.

I need to make repeated calls to a Matlab file (currently not a function) and change a certain variable each time without me doing it manually. The Matlab script then outputs to a file read by the Python files. The Python file is responsible for the final output.

The big ideas is being able to set up a line of experiments and walk away from the computer. I could also see this perhaps being more easily done in another script if it is easy to make calls from one program to the other. I haven't done any work in Matlab until this summer and have only ever used the GUI shell.

Thank you for any help you can offer and let me know if more information is necessary.

  • You can call one program, say file `program2.m`, from another, say `program1.m`. You just write `program2` within the code of `program1`, once you have defined the input variables for `program2` (perhaps in a loop) – Luis Mendo Jul 07 '14 at 16:50
  • This link (http://stackoverflow.com/questions/6657005/matlab-running-an-m-file-from-command-line) tells you how to call matlab in CLI. I didn't see mention of out arguments though. – merours Jul 07 '14 at 16:51

1 Answers1

0

There are several possible approaches for running MATLAB without a GUI and even without a MATLAB command line input:

  • start MATLAB in command line mode and call your script manually: matlab -nodesktop -nosplash

  • use a MATLAB to set the parameter and call your MATLAB script. this can be done by
    using in terminal: matlab -nodesktop -nosplash -nodisplay -r myScript

  • use a Bash script to set the parameter and the call: matlab -nodesktop -nosplash -nodisplay -r "myscript" (on Linux machines, for Windows you need to use the Power Shell)

You could then call Python from within your MATLAB scripts using the system() command to fetch your results.

Here is an example using a Bash script:

#!/bin/bash

# set parameter:
myParameter = 1 

# call MATLAB with no interface at all and send it to background
# run MATLAB function with parameter, exit afterwards
# print command window output to a textfile
matlab -nodesktop -nosplash -nodisplay -r "myMatlabFunction(${myParameter});exit" > matlab_output.txt &
Eli Duenisch
  • 516
  • 3
  • 14
  • How would I use a Bash script to set a parameter? That is one of the parts that confused me to begin with and I'm on a Mac if that makes a difference – cubsfan012512 Jul 07 '14 at 18:02
  • hi i've added an example for using Linux Bash in the answer above. the newer mac os versions use Bash as default terminal so it should work on a mac as well. – Eli Duenisch Jul 07 '14 at 18:35
  • Ended up just using another Matlab file with the system() call to the python file that you mentioned. So much easier than trying to use the terminal. Thanks! – cubsfan012512 Jul 07 '14 at 19:41
  • I can confirm that in the beginning using Bash is quite painful :) On the other hand it is nice if you want to run several scripts in parallel without using the Parallel Computing Toolbox. – Eli Duenisch Jul 07 '14 at 19:45