Find an element of a matrix equal to a constant
18 次查看(过去 30 天)
显示 更早的评论
Hi,
If B is a matrix i need to find the index of element that is equal to a constant c where the constant c is undoubtedly somewhere in the matrix.
I tried to do:
B(:,B(2,:)==c)
but there are some problems with logical operator ==
It returns me "Empty matrix"
0 个评论
回答(1 个)
Matt Fig
2011-3-29
If you are looking for the linear index:
I = find(B==c);
If you are looking for the subscript index:
[I,J] = find(B==c);
Whenever I hear somebody say they cannot find a value that they just know is in an array, I wonder if they are not about to learn the joys of floating point arithmetic.
3 个评论
另请参阅
类别
在 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!