He modificado la respuesta de Alex Cohen para mis propias necesidades, así que aquí está.
Mis requisitos eran que el script del dosificador podía manejar cadenas y enteros/entradas dobles, y que Matlab debería ejecutarse desde el directorio desde el que se llamó el script del dosificador.
#!/bin/bash
matlab_exec=matlab
#Remove the first two arguments
i=0
for var in "[email protected]"
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
Este script puede ser llamado como (si es en su camino): matlab_batcher.sh functionName stringArg1 stringArg2 1 2.0
Cuando, serán pasados los dos últimos argumentos como los números y los dos primeros como cadenas.
De MathWorks: [¿Cómo se ejecuta en modo batch MATLAB en una máquina UNIX? ] (http://www.mathworks.com/support/solutions/en/data/1-15HNG/index.html) –