MATLAB: Output argument “vec” (and maybe others) not assigned during call to “NIocr”.

MATLABmatlab function

Code attached. The function code works, but when I call the function itself, I get the error,
Output argument "vec" (and maybe others) not assigned during call to "NIocr".
I tried placing "vec" outside the loop, but then I get the error that there is no variable named t2.
The goal is to run this as an spmd so, global variables might cause trouble. Please help! Thanks.

Best Answer

After the function line, but before the "try" line, put this:
vec = [];
That will avoid the error because it will assign something (null) to vec. However you still need to figure out why the "real" value you want for vec is never getting assigned.