MatLab from the console

The following works both for Unix and Windows systems. In order to run MatLab without the graphical interface (this is handy because in this way one can get and release licenses through a script and also having the script running slightly faster) one needs to type the following (in UNIX in Windows it is similar):

nice matlab –nosplash –nodesktop

and voila!

Apart from running the MatLab instance in console one can run MatLab code from bash shell this is done with the mat command. Batch commands can be passed to MatLab by using -r command line option during invocation. By default the MatLab session keeps running. A common work around is to include a MatLab quit command explicitly in the MatLab code (the .m files), typically at the end of a simulation. An alternative is to use a wrapper script that automatically quits MatLab (a nicer solution because you can have the same code running for both instances of MatLab).

Invoking user defined M-files

mat "yourMfile_command"

Calling matlab commands

mat "help pack"

Display of workspace data

mat "a = randn(1,10); disp(a)" 

Inspecting plots (use enter key to exit the matlab session)

mat "x = sin(0:0.2:6.28); plot(sin(x));pause"

Example of a mat wrapper script:


if test "$1" = ""
echo Usage $0 \"matlab command\"

One thought on “MatLab from the console

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s