필터 지우기
필터 지우기

Remove duplicate rows based on subset of row elements

조회 수: 3 (최근 30일)
Federico Maglione
Federico Maglione 2019년 3월 5일
댓글: Vijay 2020년 9월 30일
Hello everyone,
I tried to find a similar problem - relatively simple I believe - but I could not find a solution. If, for instrance, I have a matrix such as
A = [1 1 1 100; 2 2 2 200; 3 3 3 300; 1 1 1 500]
how can I remove from A the fourth row based on the fact that only the thee first elements of the that row are identical to the three elmenets in the first row?
Also, what if I have
A = [1 1 1 100; 2 2 2 200; 3 3 3 300; 1 1 1 500; 1 1 1 600]
and, again, I just want to keep the first row?
Thank you for your help.

채택된 답변

madhan ravi
madhan ravi 2019년 3월 5일
편집: madhan ravi 2019년 3월 5일
A(unique(A(1:3),'rows'),:)
  댓글 수: 5
Federico Maglione
Federico Maglione 2019년 3월 5일
Thank you! It works perfectly
Vijay
Vijay 2020년 9월 30일
Simple, but an excellent solution.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by