Finding an element = 0 in an array
73 views (last 30 days)
Show older comments
Hi,
I have a 2 by N matrix of data that I pull from a file into Matlab that has one column of values called "X" and one column of values called "Y". I know there is one element in column "Y" that is equal to 0. I need to find what row that element is in to move forward with my program. How can I do this? I know some people use the "find" function, but I haven't been able to successfully use this. Help please!
0 Comments
Answers (1)
Star Strider
on 21 Jun 2018
You may be encountering ‘floating-point approximation error’, explained in: Why is 0.3 - 0.2 - 0.1 (or similar) not equal to zero? (link).
If that’s the problem, use a tolerance with find:
Y = [1 2 3 0.0001 4 5 -0.0009]'
Zr = find(abs(Y) < 0.01)
Zr =
4
7
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!