MATLAB: Find x for y=0 using interpolation

find a valuefind xinterpolationMATLABy=0

Hello there,
I was given the task to find the x value where y is 0 using interpolation. And I just can not figure it out on my own.
First of all: Here is my complete code:
load Daten_Wurfparabel.mat
h_index = find(y<0,1) ;
index = [ h_index-1 h_index] ;
xx = x(index) ;
yy = y(index) ;
x0 = xx(1)+1 ;
y0 = 0 ;
w = interp1( x , y , xx ) ;
% Plot
figure (1), clf
subplot(2,1,1)
hold on , grid on
plot(x ,y ,'ko-')
plot(xx,yy,'r*','markersize',10)
xlabel('x [m]'), ylabel('y [m]')
title('Wurfparabel y über x')
subplot(2,1,2)
hold on , grid on
plot(xx ,yy ,'ko-')
plot(xx,yy,'r*','markersize',10)
plot(x0, y0, 'ko')
xlim([19 21]), ylim([-0.5 1])
xlabel('x [m]'), ylabel('y [m]')
title('Vergrößerung des Nulldurchgangs')
% Ausgabe im CW
disp('Wurfweite [m] = x-Wert bei Nulldurchgang y = 0')
disp(x0(1))
As you can see. I'm loading data from a .mat file (x is a 21×1 matrix and y is a 21×1 matrix). I have attached the file below. If you paste my code into matlab, you can see that I'm off by a few centimeters. The solution should be 20.2479m and mine is currently 20.3990m.
Can someone please help me out?

Best Answer

load ("Daten_Wurfparabel.mat") ;
yi = 0 ;
xi = interp1(y,x,0) ;
[xi yi]
plot(x,y,'b')
hold on
plot(xi,yi,'*r')