You want to launch Matlab for a very long script and then disconnect your remote terminal, and when back, not finding bad surprise.
Suppose your script myeigenvalues.m is:
A=randn(1000);
X=eig(A);
save
- Create a helper script
helper_myegeinvalues.mthat launchesmyeigenvalues.mscript but surrounded by a try-catch block like this:
try
myeigenvalues;
catch ME
disp(ME);
disp('SCRIPT CRASHED');
exit;
end
disp('SCRIPT RUNNED SUCCESSFULLY');
The try-catch block is needed to avoid leaving Matlab open in idle status if an error occurred once launched as background process.
- Create another helper bash-script file
helper_myegeinvalues.shthat runs the scripthelper_myegeinvalues.m
matlab -nodisplay -nodesktop -nosplash -r "helper_myegeinvalues"
- Make the
helper_myegeinvalues.shfile executable by issuing
chmod +x helper_myegeinvalues.sh
- Run the
helper_myegeinvalues.shas a nohup command and collect all the output into the filestdout.txt
nohup ./helper_myegeinvalues.sh > stdout.txt &
- You can now leave the process run and stay happy.
Let's talk!
I'm Carlo Nicolini — I am interested on the reliability of AI reasoning systems (interpretability, inference-time methods, probabilistic language programming) and on quantitative portfolio optimization (I am a maintainer of skfolio). If you're working on something in these areas and think we might collaborate, chat, discuss, I'm happy to talk about it!
The best way to reach me is on via DM on LinkedIn.