Elements in a matrix
4 次查看(过去 30 天)
显示 更早的评论
Hello,
When I have a certain matrix, is there a possibility to check whether some value is on more than one position in the matrix.
So for example the identity matrix 3-by-3, how can I check whether the value '1' is multiple times there in the matrix?
Thanks in advance.
0 个评论
采纳的回答
更多回答(2 个)
Walter Roberson
2014-1-4
sum(TheMatrix(:) == TheValue) > 1
In the more general case where you want to know whether any value is repeated, see unique()
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!