Hi, I have the points of a curve. After I plot it, I want to find the points that the curve is on zero. I tried this code:
on1 = find(d_gsr == 0)
but matlab gave me this answer:
on1 =
Empty matrix: 1-by-0
Would anyone help me to do this?

 채택된 답변

Star Strider
Star Strider 2017년 7월 9일

1 개 추천

If you want to find the zero-crossings, this little utility function will return the indices of the approximate zero-crossings of your data:
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
Use it as:
zero_idx = zci(Your_Dependent_Data_Vector);
then to find the approximate values of your independent variable at those indices:
x_approx = Your_Independent_Data_Vector(zero_idx);
There might be a ‘false’ zero-crossing at the end of the ‘zero_idx’ vector. This is due to the wrap-around done by the circshift function. That index can be discarded.

댓글 수: 2

Ghazal Hnr
Ghazal Hnr 2017년 7월 9일
I really appreciate, your codes really help me.
Star Strider
Star Strider 2017년 7월 9일
As always, my pleasure.

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

추가 답변 (2개)

KSSV
KSSV 2017년 7월 9일

0 개 추천

You define a small value and find the abs values less then or equal to this value. This is the approach to seek the values from flottants.
theps=0.0001 ;
on1 = find(abs(d_gsr) <= theeps);

댓글 수: 1

Ghazal Hnr
Ghazal Hnr 2017년 7월 9일
편집: Ghazal Hnr 2017년 7월 9일
again it gives me the same answer

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

Image Analyst
Image Analyst 2017년 7월 9일

0 개 추천

Attach your data. Chances are there are no elements that have a pure zero as a value. I'm guessing that what you want is where your data points cross the y axis but there are actually no elements at that x location. For example if you have (x,y) = (4, 10), and the next element at (5, -3), a line connecting them will cross the y=0 line at some x value. And I'm guessing that you want the x value. But there is no element of your x array that has that value. So you'll need to find it using functions like fzero(), roots(), etc.

댓글 수: 4

Ghazal Hnr
Ghazal Hnr 2017년 7월 9일
편집: Ghazal Hnr 2017년 7월 9일
Unfortunately the website doesn't open for me correctly and I can't attach any file. the dada is in this page: https://physionet.org/physiobank/database/drivedb/
It's the hand GSR data of drive16.
I exactly want to do the same works that you said and I checked and the data doesn't have any value of zero. So I have to use fzero or roots, right?
Ghazal Hnr
Ghazal Hnr 2017년 7월 9일
편집: Ghazal Hnr 2017년 7월 9일
When I use roots it gives me too many complex numbers but due to curve I should have only 2 points.
Image Analyst
Image Analyst 2017년 7월 9일
Yes, that's one way. Or use interp1 on both x and y to get a bunch of points in between and then use the method KSSV showed you. This is a discrete approximation, which may well be close enough, rather than a theoretical/analytical answer like fzero() fill give, but for that you need to assume some model, like the "line" between points is a straight line or cubic spline, etc.
I didn't even go to the website because if you can't open the website and get the data from it, then I probably won't be able to either.
Ghazal Hnr
Ghazal Hnr 2017년 7월 9일
편집: Ghazal Hnr 2017년 7월 9일
Sorry but I'm not able to open matlab website correctly, I've already downloaded the data.
Thank you for your help.

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

태그

질문:

2017년 7월 9일

편집:

2017년 7월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by