griddedInterpolant Error: Apparent Contradiction

2 views (last 30 days)
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?
  4 Comments
John D'Errico
John D'Errico on 31 Jan 2021
New users seem to get stuck in these things. They do something without really realizing what variables or functions they have created. Then they get strange errors. Nothing makes sense. They jump to conclusions that something strange happened, when it was something they did to create the problem. I'm sorry, but we see this happen all the time.
The answer is to be more careful, to know exactly what is in your variables, to know what shape they are, etc. Are you running with the debugger turned on? If so, then if you just had an error, then you will be stuck in the wrong workspace.
The fact is, what you are seeing is not normal behavior. I (and many others) have used griddedInterpolant an uncounted number of times. If you are getting this sort of thing happening, it is something you did without knowing what you did. So go more slowly. Make sure after every step that what you just did is what you expected it to be. Ensure that your variables contain what you think they should. Make sure that if you have an error with the debugger turned on, after you resolve it, that you reset the debugger to drop you back into the base workspace!

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 31 Jan 2021
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.
  3 Comments
Walter Roberson
Walter Roberson on 31 Jan 2021
... and just in case, use "which" to test that things you expect to be functions, really are functions, and that you are getting the right version of the function.
Image Analyst
Image Analyst on 31 Jan 2021
@David Cyncynates next time, post the full error message (ALL the red text including line numbers of actual lines of code and traceback), and code and data so we can reproduce it.

Sign in to comment.

More Answers (0)

Categories

Find more on Performance and Memory in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!