Simple Interpolation
You could just interpolate the other way...
% Your code
x = [1 2 3 4 5 6 7 8 9];
y = [1 2 3 4 5 4 2 6 8];
xq = [1:0.25:9];
yq = interp1(x, y, xq);
% Interpolate your newly interpolated xq and yq to find x = x1 when y = 3.5
x1 = interp1(yq, xq, 3.5)
Finding Zeros
This approach is more complicated but, depending on your data, may be more applicable.
You could use some sort of root finding approach using fzero
, and a function defined as below
% Initialise
x = [1 2 3 4 5 6 7 8 9]; y = [1 2 3 4 5 4 2 6 8];
% Define function, like your interpolation, which will have a zero at x=x0
% when y = y0.
y0 = 3.5;
yq = @(xq) interp1(x, y, xq) - y0
% find the zero, intial guess must be good enough
y0 = fzero(yq, 1)
As noted in the comments, the intial guess must be "good enough" - this is not only for convergence within fzero
but if, during the evaluation, a value of x is tested which is outside of your interpolation then it will break.
Example:
y0 = fzero(yq, 1)
% >> Exiting fzero: aborting search for an interval containing a sign change
% because NaN or Inf function value encountered during search.
% (Function value at 0.971716 is NaN.)
y0 = fzero(yq, 5)
% >> y0 = 3.5, as expected from the input data.