Hello,
I have some data and i want to run this code:
xi = [85];
yi = interp1(y,x,xi)
but I have this error:
Error using griddedInterpolant
The grid vectors are not strictly monotonic increasing.
Error in interp1 (line 183)
F = griddedInterpolant(X,V,method);
Error in Q4 (line 19)
yi = interp1(y,x,xi)
How can I fix it?

 채택된 답변

Star Strider
Star Strider 2017년 3월 12일
편집: Star Strider 2017년 3월 12일

0 개 추천

One way (without seeing your data, so this is a guess on my part):
y85 = find(y <= 85, 1, 'last');
yi = interp1(y(y85-1:y85+1),x(y85-1:y85+1),xi, 'linear','extrap');
That is how I would do it. This assumes there is only 1 where ‘y’ is approximately 85.
Note This is obviously UNTESTED CODE. It should work, if there is one ‘y’ near 85.
EDIT Added the 'extrap' option to make my approach more robust.

댓글 수: 4

Ghazal Hnr
Ghazal Hnr 2017년 3월 12일
편집: Ghazal Hnr 2017년 3월 12일
There is only one where y is 85.
I use your code but i still have error:
Index exceeds matrix dimensions.
Error in Q4 (line 20)
yi = interp1(y(y85-1:y85+1),x(y85-1:y85+1),xi, 'linear','extrap')
Star Strider
Star Strider 2017년 3월 12일
편집: Star Strider 2017년 3월 12일
Without your data, I cannot tell.
Try this:
yi = interp1(y(y85-1:y85),x(y85-1:y85),xi, 'linear','extrap')
or this:
yi = interp1(y(y85:y85+1),x(y85:y85+1),xi, 'linear','extrap')
One of them should work.
Also, be certain you are interpolating the correct value. If you want the value of ‘y’ at ‘x=85’, do this instead:
yi = interp1(x, y, xi, 'linear','extrap')
You may have misinterpreted the documation for interp1.
Ghazal Hnr
Ghazal Hnr 2017년 3월 13일
thanks my problem solved
Star Strider
Star Strider 2017년 3월 13일
My pleasure.

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

추가 답변 (1개)

John D'Errico
John D'Errico 2017년 3월 12일

0 개 추천

The fix is easy. Don't use interp1 to interpolate data that is not strictly monotone in the independent variable.
After all, how can interp1 know which value to predict on a function that is apparently multi-valued? For example, consider points around the perimeter of acircle. For any given x, there are TWO solutions. Interp1 requires a single valued function for any given x.

카테고리

도움말 센터File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

태그

질문:

2017년 3월 12일

댓글:

2017년 3월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by