MATLAB: Want to find and use a corresponding y-value for a given x-value

middle point x y array point corresponding value

I'm trying to find the value of y when x is at half max – i.e. when x = 50, what does y equal? I then need to use that y-value in further calculations, so I need to assign it a name or have it returned somehow. The lists of numbers I will be using goes from x=0 to 100 in about 600+ steps and 50 is not in the same location in every data set, so none of the help in the interpolation/max/median type areas has been helpful so far, I don't know what keywords to use to get successful search in MATLAB help. (I think this is probably simple however I am a new user so thanks for the help)

Best Answer

%Sample x/y
x = linspace(0,100,572);
y = 2.*x.^2-31*x;
%Index of x closest to 50 and corresponding y
[junk, idx50] = min(abs(x-50));
y50 = y(idx50);
NOTE: This isn't interpolating, just extracting the closest value to 50. Do you need an interpolation to 50 exactly?