Showing posts with label with. Show all posts
Showing posts with label with. Show all posts

"Open With" Matlab—How-To for Linux

This post explains how to set .m (matlab source code files) to open with Matlab (a how-to for Gnome Linux).
  1. Right-click a .m file and click Properties
  2. Click the Open With tab then click Add
  3. Expand Use custom command and type the following into the field:
matlab -desktop -r "f=%f; cd(fileparts(f)); edit(f); clear f;"
  1. Click Add then select the radio button next to matlab.
  2. Close the property window.
Now all of your .m files should open with Matlab. The only thing I can't fix is that a new instance of Matlab is opened every time you open a .m file. To help, I set the current directory in Matlab to be that of the .m file which is being opened. Now you should be able to open your other .m files in Matlab more easily, without opening multiple instances.

If you'd like to know what that command does:

matlab: to run Matlab
-desktop: to run Matlab without using a terminal
-r: execute following matlab code when Matlab opens
f=%f: Save filename of file to open to variable f
cd(fileparts(f)): change the current directory to file f's directory
edit(f): open file f for editing
clear f: delete the matlab variable f