views:

109

answers:

2

Since MathWorks release a new version of MATLAB every six months, it's a bit of hassle having to set up the latest version each time. What I'd like is an automatic way of configuring MATLAB, to save wasting time on administrative hassle. The sorts of things I usually do when I get a new version are:

  1. Add commonly used directories to the path.

  2. Create some toolbar shortcuts.

  3. Change some GUI preferences.

The first task is easy to accomplish programmatically with addpath and savepath. The next two are not so simple.

Details of shortcuts are stored in the file 'shortcuts.xml' in the folder given by prefdir. My best idea so far is to use one of the XML toolboxes in the MATLAB Central File Exchange to read in this file, add some shortcut details and write them back to file. This seems like quite a lot of effort, and that usually means I've missed an existing utility function. Is there an easier way of (programmatically) adding shortcuts?

Changing the GUI preferences seems even trickier. preferences just opens the GUI preference editor (equivalent to File -> Preferences); setpref doesn't seems to cover GUI options.

The GUI preferences are stored in matlab.prf (again in prefdir); this time in traditional name=value config style. I could try overwriting values in this directly, but it isn't always clear what each line does, or how much the names differ between releases, or how broken MATLAB will be if this file contains dodgy values. I realise that this is a long shot, but are the contents of matlab.prf documented anywhere? Or is there a better way of configuring the GUI?

For extra credit, how do you set up your copy of MATLAB? Are there any other tweaks I've missed, that it is possible to alter via a script?

+1  A: 

At the moment, I'm not using scripts, though this sounds like a very interesting idea.

Unless there are new features that you also want to configure, you can simply copy-paste the old preferences into the new prefdir. I guess this should be doable programmatically, though you might have to select the old prefdir via uigetdir. So far, this has not created major problems for me. Note also that in case of a major change in the structure of preferences, any programmatic version would have to be rewritten as well.

I'm adding paths at each startup, so that I don't need to think of manually adding new directories every time I change something in my code base (and I don't want to have to update directory structures for each user). Thus, I also need to copy-paste startup.m for each installation.

If I had to do everything manually, I'd also want to change the autosave options to store the files in an autosave directory. If I recall correctly, Matlab reads the colors and fonts from previous installations, so I don't have to do that.

Jonas
Cheers. I agree about adding paths as you go; otherwise the path can get crazy. I have a couple of non-project-specific paths that I add permanently, then a function for each project that adds project-specific paths, changes the `cd` and does other startup tasks. Also, good call about the autosave directory; those `asv` files do get in the way.
Richie Cotton
+1  A: 
  1. shortcuts - read here and here

  2. preferences - read http://undocumentedmatlab.com/blog/changing-system-preferences-programmatically/

Yair Altman
Thanks for this; just what I wanted.
Richie Cotton