If you execute
dbstop if error
on the command line and then run the script, the debugger will stop on line 322, which is
XYZ = XYZ + repmat([pn;pe;pd],1,size(XYZ,2));
If at that point you execute
whos
on the command line, you'll see this:
K>> whos
Name Size Bytes Class Attributes
XYZ 3x39 936 double
pd 1x101 808 double
pe 1x101 808 double
pn 1x1 8 double
which tells you that pn, pe, and pd cannot be vertically concatenated, i.e., this part
[pn;pe;pd]
is not going to work, since they don't have the same number of columns. That's the reason for the specific error.