how can i find identical rows in a matrix
77 ビュー (過去 30 日間)
古いコメントを表示
I have a 158x7 matrix. I want to find if there is at least one row which is identical.
2 件のコメント
Geoff Hayes
2015 年 3 月 21 日
AA - please describe what you mean by similar. Do you meant that the two rows are identical or share the same values or share a pattern of numbers? Be clear about what the problem is you are trying to solve. Use the question body to include more than just a repeat of your question header.
採用された回答
Konstantinos Sofos
2015 年 3 月 21 日
編集済み: Konstantinos Sofos
2015 年 3 月 21 日
Use unique() to find the distinct row values. If you end up with fewer rows, there are duplicates. It'll also give you indexes of one location of each of the distinct values. All the other row indexes are your duplicates.
x = [
1 1
2 2
3 3
4 4
2 2
3 3
3 3
];
[u,I,J] = unique(x, 'rows', 'first')
hasDuplicates = size(u,1) < size(x,1)
ixDupRows = setdiff(1:size(x,1), I)
dupRowValues = x(ixDupRows,:)
0 件のコメント
その他の回答 (1 件)
参考
カテゴリ
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!