Watch this Author's files
I've pinpointed the issue with the "Index exceeds matrix dimensions." error and it's a bug somewhere else.
It has to do with "hold on" somehow adding 2 new tick marks to the figure.
Here is how to reproduce it on 2012a:
dat = 1:5;
fh = figure;
If you would remove "hold on", no error.