Saturday, April 3, 2010

Current work directory in Matlab at startup time

I use Matlab on a daily basis for the post-processing and preliminary visualization of my simulation datasets.

Every time I upgrade Matlab to a newer version I face the following issue:

when Matlab starts, the current work directory is set to a default value, inside Matlab directory tree itself.

This default directory is of no use for me. Usually, I prefer to have as current work directory at startup time the one with which I've been working most recently.

To setup your preferred current work directory at startup time, you just need to run once the command


userpath('my preferred current work directory')

Next time you run Matlab, it will automatically setup your chosen directory as the current work one.

If you run Matlab via an shortcut icon on your desktop, under MS Windows, just be sure that the "Start in" field of the shortcut is empty (see image below) otherwise the directory you chose and setup via the
userpath(...) command will be overwritten by the one inserted in the shortcut's "Start in" field.