To debug a function that is part of a larger set of codes, perhaps you should use debugging features such as code breaks and dbstop if error. This is an example workthrough for debugging complex codes:
Error: Something went wrong in functionA line 145 etc etc
>> dbstop if error
If your code runs into an error, your editor will open to the error line to help you debug. You'll need to traverse the Function Call Stack to find the function that really needs the fix. For instance, if functionA calls functionB with incorrect inputs, and functionB throws the error message, the dbstop will stop in functionB when you actually need to fix functionA. Go to Function Call Stack > functionA.m to debug functionA.
With dbstop, the local variables are given to you so you can figure out what's the issue.