4
votes

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.

2
Matlab should stay open, does the file call quit or similar? - Daniel
I'm afraid I don't have an answer for your question - sorry. I've only very recently started using SublimeText, together with MATLAB, and it sounds like you have more experience with that combination. Would you mind sharing your experience briefly in a comment? For example, have you customized the syntax checker, or extended the tab-completion at all for the MATLAB language? And are you integrating SublimeText with MATLAB at all, or just replacing the MATLAB editor? Many thanks for your suggestions. - Sam Roberts
@Sam Roberts I love Sublime for its cool functions like transposing text and the GoTo anything. This makes it superior to the Matlab editor to me. For autocompletion there is a snippet collection available here github.com/AGS-Knight/matlab-snipp The build system also works extremely fast using octave, which might be interesting to you too: { "cmd": ["octave", "--silent", "$file"] } - Eli Duenisch

2 Answers

6
votes

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.

0
votes

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:

  1. You maintain all of the useful features of MatLab as an IDE
  2. You can evaluate code snippets (the F9 feature) as well as the whole file

See detailed instructions for Linux or Windows