フィルターのクリア

Find out the rows having same values in all columns of a matrix

51 ビュー (過去 30 日間)
Sky Scrapper
Sky Scrapper 2018 年 11 月 26 日
コメント済み: Sky Scrapper 2019 年 1 月 24 日
Hi,
I have a matrix with 4374 rows and 8 columns. I need to find the rows which have all the columns are of same values and it's repeated for 6 times.
As for example,
Let us consider a matrix, A= [ 0 0 0 0 1 0 0 ; 1 0 0 0 0 1 0; 1 0 0 0 0 1 0; 0 1 0 1 0 1 0; 1 0 0 0 0 1 0; 0 0 0 0 0 0 0; 1 0 0 0 0 1 0, 1 1 1 1 1 1 1; 1 0 0 0 0 1 0 , 0 0 1 1 0 1 0; 1 0 0 0 0 1 0; 0 0 0 0 1 0 0].
Here,0 0 0 0 1 0 0 is repeated twice and 1 0 0 0 0 1 0 is repeated for 6 times. Finally, I need to find and keep only those rows having repeated for 6 times (as like 1 0 0 0 0 1 0 in the given example) .
Can any please help me?

採用された回答

Stephen23
Stephen23 2018 年 11 月 26 日
編集済み: Stephen23 2018 年 11 月 26 日
Something like this should get you started:
>> A = [0,0,0,0,1,0,0;1,0,0,0,0,1,0;1,0,0,0,0,1,0;0,1,0,1,0,1,0;1,0,0,0,0,1,0;0,0,0,0,0,0,0;1,0,0,0,0,1,0;1,1,1,1,1,1,1;1,0,0,0,0,1,0;0,0,1,1,0,1,0;1,0,0,0,0,1,0;0,0,0,0,1,0,0]
A =
0 0 0 0 1 0 0
1 0 0 0 0 1 0
1 0 0 0 0 1 0
0 1 0 1 0 1 0
1 0 0 0 0 1 0
0 0 0 0 0 0 0
1 0 0 0 0 1 0
1 1 1 1 1 1 1
1 0 0 0 0 1 0
0 0 1 1 0 1 0
1 0 0 0 0 1 0
0 0 0 0 1 0 0
>> [U,~,idx] = unique(A,'rows');
>> cnt = histc(idx,unique(idx)) % count how many times rows occur.
cnt =
1
2
1
1
6
1
>> out = U(cnt==6,:) % pick which the unique rows which occur >= 6 times.
out =
1 0 0 0 0 1 0
If you want to get those multiple row instances, then try this:
>> idr = ismember(idx,find(cnt==6));
>> A(idr,:)
ans =
1 0 0 0 0 1 0
1 0 0 0 0 1 0
1 0 0 0 0 1 0
1 0 0 0 0 1 0
1 0 0 0 0 1 0
1 0 0 0 0 1 0
  9 件のコメント
Stephen23
Stephen23 2019 年 1 月 24 日
編集済み: Stephen23 2019 年 1 月 24 日
Perhaps this is what you are looking for:
[~,idy,idx] = unique(A(:,5:11),'rows')
U = A(idy,:)
If not you will have to show what the expected output should be.
Sky Scrapper
Sky Scrapper 2019 年 1 月 24 日
yes, that's I want. thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by