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일

8 개 추천

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일

3 개 추천

A = [1 2 3; 3 4 5; 1 2 3];
[C,ia,ic] = unique(A,'rows') ;
iwant = zeros(size(A)) ;
iwant(ia,:) = C ;

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

질문:

2016년 10월 6일

답변:

2016년 10월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by