This is the expected behavior because when MATLAB has been started without the desktop, it expects to be able to read from standart input ('stdin'), however, when you start it in the background, it cannot read from 'stdin' and the process will be stopped.
As a workaround, you can create a text file which includes the commands you want to execute and use input redirection operator "<" instead of "-r" option. For example, assuming the file "foo.txt" includes the lines
you can execute the command
matlab -nodisplay -nodesktop -nojvm -nosplash <foo.txt >out.txt &
As another workaround, you can write a shell script which automates the process.
Best Answer
In order to start your MATLAB process through the SSH connection and leave it running after you disconnect, you need to use the following commands on the csh/tcsh shell on the Mac:
The file 'mybgprocess.m' contains the MATLAB commands that you want to run. It is important that this function has a QUIT or EXIT statement at the end so that the MATLAB process is closed after you script is done executing. The file 'mystdio.txt' can be an empty file, but it needs to exist. Without this file, the standard input of the MATLAB process would be empty, which would cause the MATLAB process to die. The file 'matlab.out' will store the output of the MATLAB Command Window to your commands.