griddedInterpolant Error: Apparent Contradiction

조회 수: 2 (최근 30일)
David Cyncynates
David Cyncynates 2021년 1월 30일
댓글: Image Analyst 2021년 1월 31일
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
John D'Errico
John D'Errico 2021년 1월 31일
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!
David Cyncynates
David Cyncynates 2021년 1월 31일
I'm certain that you are correct @John D'Errico

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
Steven Lord 2021년 1월 31일
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
Walter Roberson
Walter Roberson 2021년 1월 31일
... 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 2021년 1월 31일
@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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by