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

 채택된 답변

Star Strider
Star Strider 2016년 10월 26일

0 개 추천

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

aryan abedi
aryan abedi 2017년 7월 19일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

태그

질문:

2016년 10월 26일

댓글:

2017년 7월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by