I have modified Alex Cohen's answer for my own needs, so here it is.
My requirements were that the batcher script could handle string and integer/double inputs, and that Matlab should run from the directory from which the batcher script was called.
#!/bin/bash
matlab_exec=matlab
#Remove the first two arguments
i=0
for var in "$@"
do
args[$i]=$var
let i=$i+1
done
unset args[0]
#Construct the Matlab function call
X="${1}("
for arg in ${args[*]} ; do
#If the variable is not a number, enclose in quotes
if ! [[ "$arg" =~ ^[0-9]+([.][0-9]+)?$ ]] ; then
X="${X}'"$arg"',"
else
X="${X}"$arg","
fi
done
X="${X%?}"
X="${X})"
echo The MATLAB function call is ${X}
#Call Matlab
echo "cd('`pwd`');${X}" > matlab_command.m
${matlab_exec} -nojvm -nodisplay -nosplash < matlab_command.m
#Remove the matlab function call
rm matlab_command.m
This script can be called like (if it is on your path):
matlab_batcher.sh functionName stringArg1 stringArg2 1 2.0
Where, the final two arguments will be passed as numbers and the first two as strings.