Searching a Matrix for Specific Values
1 次查看(过去 30 天)
显示 更早的评论
I need to look for occurrences of values in a matrix, namely instances in a matrix where the rows contain the following:
1. The numbers 1 2 3 4 5, in any order 2. the number '2' twice in the same row 3. The row is comprised of entirely the same number.
Thank you
2 个评论
回答(1 个)
John Petersen
2012-11-21
For matrix A
thisrow = A(row,:);
result1 = (any(thisrow,1) && any(thisrow,2) && any(thisrow,3) && any(thisrow,4) && any(thisrow,5));
This will do the first case you posed. result1 will be 1 if the row contains 1,2,3,4,&5, and will be 0 if it doesn't. This should get you started.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Encryption / Cryptography 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!