Finding an element = 0 in an array
68 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!