find x intercepts numerically

조회 수: 7 (최근 30일)
Elizabeth Ramsey
Elizabeth Ramsey 2020년 5월 25일
댓글: Elizabeth Ramsey 2020년 5월 25일
I'm trying to find a quick way of returning the index of all the places where an [x,y] data set crosses the x axis.
I've tried: zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0)
But it isn't returning all the zeros and also always returns the last value in my dataset as a zero even though it isn't. I'm testing with a third order polynomial and can only get my code to work if it have only one root.
Thanks!

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 25일
편집: Ameer Hamza 2020년 5월 25일
Try this
f = @(x) find(diff(sign(x)));
Example
>> x = [1 2 -1 -2 -1 2 3 1 -2 -3 -2 1];
>> f(x)
ans =
2 5 8 11
  댓글 수: 1
Elizabeth Ramsey
Elizabeth Ramsey 2020년 5월 25일
Exactly what I needed, thanks so much!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by