I set up a build system in Sublime Text 3 to run Matlab files. This works really fine:
{
"cmd": ["/usr/local/MATLAB/R2013b/bin/matlab", "-nosplash", "-nodesktop", "-nojvm", "-r \"run('$file');\""]
}
The problem is I want to keep Matlab running in the Sublime console after $file is executed. Is this possible?
Thank you in advance.
Ok, I've finally found a solution that runs the build system in an external xterm terminal. If you use this Sublime will open a xterm window and execute the build system there. This window remains open, so e.g. Matlab plot windows will not be closed after execution of the code. I've combined the build system with and without the external terminal into one build system:
{
"cmd": ["/usr/local/MATLAB/R2013b/bin/matlab", "-nosplash", "-nodesktop", "-r \"run('$file');quit;\""],
"selector": "source.m",
"variants": [
{
"name": "xterm",
"cmd": ["xterm", "-e", "/usr/local/MATLAB/R2013b/bin/matlab", "-nosplash", "-nodesktop", "-r \"run('$file');\""]
}
]
}
and then assigned a user key binding to access the xterm variant easily:
[
{ "keys": ["ctrl+shift+b"], "command": "build", "args": {"variant": "xterm"} }
]
This xterm solution should also work with any other interpreter that you want to prevent from being closed after code execution finishes.
An alternative method is to have both Sublime and Matlab open and then set up a script with AutoHotKey (Windows) or Autokey (Linux) that copies the filename or the code to evaluate and then pastes this in Matlab's command window.
The benefits of this method are:
- You maintain all of the useful features of MatLab as an IDE
- You can evaluate code snippets (the F9 feature) as well as the whole file
See detailed instructions for Linux or Windows