Howto Run a Matlab Script With a Shell

Please use an editor that you like to write a matlab script as following:

a=3;
b=2;
c=a+b

Save as num.m (a matlab script).

Then, use the editor vi or gedit to write a shell script as following:

1
2
3
4
5
6
7
8
9
10
#!/bin/sh
#
# File: num.sh
# Description:
# running a matlab script from within a shell script.
#
# Created Date: August 1st,2010
# Author: Mutse Young <yyhoo2.young@gmail.com>
#
matlab -nodesktop -nosplash -r “num;quit”

Save as a shell script num.sh.

Now, you can run the matlab script from within a shell script as follows:

1
2
$ chmod a+x num.sh
$ num.sh

There is a result string information printed on the terminal, showed as following:

Warning: Could not access OpenGL library 

                          < M A T L A B > 
              Copyright 1984-2004 The MathWorks, Inc. 
                     Version 7.0.0.19901 (R14) 
                            May 06, 2004 


  To get started, type one of these: helpwin, helpdesk, or demo. 
  For product information, visit www.mathworks.com. 

c = 

	5