MATLAB: Find X-value given Y

find xinterp1interpolationintersectionlog10logarithmic

Hello
I've been doing some research regarding this but I can't seem to find a solution for when I want to find the X-value given Y.
I have the following data:
>> X
ans =
20 50 100 200 500 1000 2000 5000 10000 20000
>> Y
ans =
-0.1755 -0.1755 -0.9151 -2.8534 -8.4043 -13.1515 -20.0000 -27.5350 -33.9794 -40.0000
Where the X is plotted on a logarithmic scale. I tried interp1 with X and Y switched but that dosent work since its not strictly monotonic increasing.
Does anyone have a solution on this? Say I want to find the value of X given Y=-5

Best Answer

The ‘x’ and ‘y’ vectors were not the same sizes, so I added 25 to ‘x’, then added a small amount to the duplicated element in ‘y’ and did the interpolation:
x = [25 50 100 200 500 1000 2000 5000 10000 20000];
y = [ -0.1755 -0.1755 -0.9151 -2.8534 -8.4043 -13.1515 -20.0000 -27.5350 -33.9794 -40.0000];
dy = diff([0 y]);
dyix = find(dy == 0);
y(dyix) = y(dyix-1)+1E-8;
xint = interp1(y, x, -10); % Find The Value Of ‘x’ Corresponding To y=-10’