Friday, April 27, 2012

Calling Matlab Functions from Linux Terminal

I had been thinking of how could I call Matlab functions from command line in a Linux environment and pass arguments to it. This post will elaborate on that. 

For starters, lets see how to call Matlab scripts in linux environment

matlab -nodisplay -nosplash -nojvm < sample.m > Output.txt

The sample.m   will run just as it would have ran if you would have started it from Matlab command prompt. Now lets see how would you call functions in the same way. The crucial part is how to pass arguments to the function

matlab -nodisplay -nosplash <<EOF

cd $WHERE_YOUR_FUNCTION_LIVES

My_Function( arg1, arg2 )

EOF


I hope this is of some help to you. Feel free to comment with your suggestions, queries, or ideas. I would be more than happy to help you.

Regards, 
Hrushikesh