필터 지우기
필터 지우기

Removing rows with identical column value

조회 수: 2 (최근 30일)
Miguel L
Miguel L 2015년 12월 27일
댓글: Miguel L 2015년 12월 27일
Hello. I have a 2 x 3 matrix.
I want to delete all rows which have the same elements in column 3.
For instance: a = [2,7; 3,4; 3,7] => [3,4]
In this case, as number 7 was repeated in row 1 and row 3, both rows are removed.
Thanks in advance.

채택된 답변

harjeet singh
harjeet singh 2015년 12월 27일
hello miguel use this code
clear all
close all
clc
a = [2,7; 3,4; 3,7];
b=[];
for i=1:size(a,1)
[r,c]=find(a(:,1)==a(i,1));
if(length(r)==1)
b=[b;a(i,:)];
end
end
b
  댓글 수: 1
Miguel L
Miguel L 2015년 12월 27일
It works very nice Harjeet Singh. Thanks.

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

추가 답변 (1개)

Star Strider
Star Strider 2015년 12월 27일
a = [2,7; 3,4; 3,7];
[Au,ia,ic] = unique(a(:,2), 'stable');
rep = accumarray(ic, 1);
rows = find(ic == ic(rep<2));
Result = a(rows,:)
Result =
3 4

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by