Filter löschen
Filter löschen

Finding an element = 0 in an array

84 Ansichten (letzte 30 Tage)
Alexandria Will-Cole
Alexandria Will-Cole am 21 Jun. 2018
Beantwortet: Star Strider am 21 Jun. 2018
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!

Antworten (1)

Star Strider
Star Strider am 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

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by