Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB: How to run a different file than the one being edited?

Tags:

matlab

I (unfortunately) have a MATLAB project with two files, main.m and function.m. I spent my time editing function.m, which is called several times from main.m. When I press F5 on the keyboard, it runs the current file (function.m) so i need to keep changing back to main.m to run the project, which is irritating. I am used to eclipse that will run the last launched.

Is there a way to effect that behaviour in MATLAB?

If any potential employers are reading this, please note that I am forced to use this program (which charges customers for access to thread-safe primitives) against my will.

like image 845
gub Avatar asked Feb 09 '11 17:02

gub


3 Answers

Choose "Edit Run Configurations for function.m" in the run menu and write your custom line (main). See attached image. enter image description here

like image 145
Lordalcol Avatar answered Nov 01 '22 15:11

Lordalcol


If you're okay with clicking a button instead of hitting F5, you could make a "Run main" button in the shortcuts toolbar. In the main Matlab window, right-click the menu and turn on the Shortcuts toolbar if it's not on already. Right-click the shortcut toolbar, "new shortcut", put "Run main" in the label, and enter "main()" for the callback. This will work regardless of what file you're editing, and you could set up additional shortcuts for alternate run configurations if you get to that point.

I don't think you can define key bindings for these shortcuts. But if you really want it, Yair Altman's Undocumented Matlab site has a hack for adding arbitrary user defined key bindings that could probably be used here.

like image 20
Andrew Janke Avatar answered Nov 01 '22 15:11

Andrew Janke


You could separate the windows into two external edit windows and use Alt + Tab to switch and then F5?

like image 37
Brendan Avatar answered Nov 01 '22 15:11

Brendan