MATLAB: GriddedInterpolant Error: Apparent Contradiction

errorgriddedinterpolantMATLAB

I have some code that uses griddedInterpolant, and it runs fine for the most part. However, there is the rare case where it spits out the error
"Not enough input arguments"
or
"Index in position 1 is invalid. Array indices must be positive integers or logical values."
I thought "that's strange, I'd better check that the inputs are sensible," so I set up my code to throw an error report with a list of the input values. I then re-inserted those input values into my griddedInterpolant, and it didn't throw an error! I have absolutely no idea what's going on – the gridded interpolant works for the values that cause it to throw an error!?
Have you ever seen griddedInterpolant throw these errors before? What was the remedy?

Best Answer

Rather than using a separate report to debug this issue, set an error breakpoint. When it stops on a line where you create or use a griddedInterpolant look at the code that's being executed on that line and what variables you're using on that line.
If you don't see anything that explains to you what could cause that error, show us the line and the variables used on that line. The output of whos listing the class, size, and attributes of those variables may be useful.
Related Question