Thursday, August 2, 2012

Jacob's MATLAB functions

I've used MATLAB for most of my plotting needs for over a year, so most of my "final" plotting scripts are written in MATLAB.  During that time, I wrote a number of custom functions that get shared across all my scripts.  Unfortunately, they aren't included in the scripts themselves, so if you want to use my scripts you'll need to manually add them to your MATLAB path so matlab can see them.  If you don't, you'll see errors like "Undefined function or variable 'strrep_many'" when you try to run my scripts.

These functions are stored on Sox.  They can be found in 3 directories:
  • /Users/oberman/Documents/MATLAB/ColorUtils
  • /Users/oberman/Documents/MATLAB/MiscUtils
  • /Users/oberman/Documents/MATLAB/TimeUtils

If you already know how to add folders to the MATLAB path (and/or already have a folder where you keep custom functions), just take the scripts out of those 3 directories and put them somewhere on your path.  You'll be good to go.


If not, you'll need to either modify your startup.m file or create one if you don't have it.  startup.m is a MATLAB script that runs as soon as the program boots up.  It can execute any commands you like; here, we're going to use it to add my folders to your path so MATLAB can see the functions within them. 

The default location that MATLAB looks for a startup.m file is in the folder ~/Documents/MATLAB/, where ~ is your home directory.  If you don't have a /Documents/MATLAB/ folder, try starting MATLAB and then exiting.  It should exist after you've started MATLAB once.  Create a file in that folder called "startup.m" and in it put the following lines:
addpath('/Users/oberman/Documents/MATLAB/ColorUtils');
addpath('/Users/oberman/Documents/MATLAB/TimeUtils');
addpath('/Users/oberman/Documents/MATLAB/MiscUtils');
Now, next time you start MATLAB, my functions should work just as if they were built in.  You are of course welcome to add other lines to your startup.m (it uses the MATLAB scripting language).  You can also copy my scripts to another location and add that folder instead - this might be helpful if you want to modify or expand on something I did.

No comments:

Post a Comment