フィルターのクリア

identify duplicate rows in a matrix

51 ビュー (過去 30 日間)
Ananya Malik
Ananya Malik 2016 年 10 月 6 日
回答済み: KSSV 2016 年 10 月 6 日
I have a matrix
A = [1 2 3; 3 4 5; 1 2 3];
I want to identify the duplicate row i.e. 3rd row and replace the values in that row by 0.
Resultant A = [1 2 3; 3 4 5; 0 0 0];
Is there an efficient way to do this? Thanks in Advance.

採用された回答

Massimo Zanetti
Massimo Zanetti 2016 年 10 月 6 日
You can identify the repeated rows by invoking unique function of Matlab, and then set to 0 non-unique rows as follows:
[C,ia,ib]=unique(A,'rows','stable');
i=true(size(A,1),1);
i(ia)=false;
A(i,:)=0;
Then A will be your output.

その他の回答 (1 件)

KSSV
KSSV 2016 年 10 月 6 日
A = [1 2 3; 3 4 5; 1 2 3];
[C,ia,ic] = unique(A,'rows') ;
iwant = zeros(size(A)) ;
iwant(ia,:) = C ;

カテゴリ

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