필터 지우기
필터 지우기

Finding an element = 0 in an array

조회 수: 84 (최근 30일)
Alexandria Will-Cole
Alexandria Will-Cole 2018년 6월 21일
답변: Star Strider 2018년 6월 21일
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!

답변 (1개)

Star Strider
Star Strider 2018년 6월 21일
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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by