function [ywant] = linterp(x,y,xwant)
%
% x,y vectors of length n
%
% xwant is the value we want to interpolate
% ywant is the estimate of the y value at xwant
% search through vector of x coordinates looking for the
% 2 x values that bracket xwant
n = length(x);
for i = 1:n-1 % n-1 comparisons to do
if(xwant > x(i) && xwant < x(i+1))
x1 = x(i);
x2 = x(i+1);
y1 = y(i);
y2 = y(i+1);
m = (y2-y1)/(x2-x1);
b = y1 - m*x1;
ywant = m*xwant + b;
return % stop processing function and go back to script file
end
end