I want to know the value of x_0 at specific y_0 using interpolation

2 views (last 30 days)
Hello All, I have a strictly monotone vector x and some repeated values of y, and I want to know the value of x_0 at specific y_0 using "interp1" but I face a message "The grid vectors are not strictly monotonic increasing"
for example
x=-2:5;
y=[3 3 8 15 24 35 48 48];
yint=interp1(y,x,9);

Accepted Answer

Star Strider
Star Strider on 24 Jun 2015
A useful technique for dealing with repeated elements is to add very small amounts to the repeated values. This works for two or more repeated values, and does not introduce significant error:
x=-2:5;
y=[3 3 8 15 24 35 48 48];
dy = diff([0 y]);
inc = (dy==0) .* [1:length(y)]*eps*10;
y = y + inc;
yint=interp1(y,x,9);
This calculates ‘yint’ as 0.143.
  5 Comments
Ahmad Alhasanat
Ahmad Alhasanat on 25 Jun 2015
Thank you so much guys.
It works well in my codes ...
I used the idea that dpb suggested for some previous work, but I need here to use this interpolation in "for" loop, where the repeated value(s) is not y(1) or y(end) at all time!
Thank you again.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!