Hello I am plotting X vs Y and would like to know what is the value of X when Y is equal to zero. I think it is the x intercept. the graph is not really simple its like a wave and I would like to know the first x intercept only. thanks

 Respuesta aceptada

Star Strider
Star Strider el 26 de Oct. de 2016

0 votos

Something like this will do what you want:
x = linspace(0, 10, 250); % Create Data
y = cos(2*pi*x) + x/5; ` % Create Data
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
y_idx = zci(y); % Approximate Indices Of Zero-Crossings
idx_rng = y_idx(1)-1:y_idx(1)+1; % Index Range Near First Zero-Crossing
first_zero = interp1(y(idx_rng), x(idx_rng), 0, 'linear','extrap'); % Interpolate To Find ‘x’ Of First Zero Crossing, Allow For Extrapolation If Necessary
figure(1)
plot(x, y)
hold on
plot(first_zero, 0, 'gp', 'MarkerSize',10, 'MarkerFaceColor','g')
hold off
grid

1 comentario

aryan abedi
aryan abedi el 19 de Jul. de 2017
I used the same code but I got an error. I was wondering if you could help me please. I know I have to zero crossing analysis but I have no idea how to.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 26 de Oct. de 2016

Comentada:

el 19 de Jul. de 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by