Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How can i get the output?

조회 수: 1 (최근 30일)
VIJAY
VIJAY 2017년 9월 14일
마감: MATLAB Answer Bot 2021년 8월 20일
i have the matrix
A=[1 2 4;
1 2 3;
4 5 6;
7 8 9;
4 5 8;
9 1 3];
i hope to compare first two column only comparison in the matrix so i need the output as
A=[7 8 9;
9 1 1]
  댓글 수: 1
KSSV
KSSV 2017년 9월 14일
How this output comes?

답변 (1개)

Rik
Rik 2017년 9월 14일
I'm going out on a limb here: I will assume your question is how to remove all rows where the first two values are non-unique. This rephrasing immediately points to the solution: use the unique function with the 'row' switch and the additional output (the position). Then we count occurrences with hist and remove all rows with an occurrence not equal to 1.
A=[1 2 4;
1 2 3;
4 5 6;
4 5 8;
9 1 3;
7 8 9];
[~,indexInMatrix,positionOfRowInUniqueVector]=unique(A(:,1:2),'rows','stable');
[numOfOccurrences,~]=hist(positionOfRowInUniqueVector,unique(positionOfRowInUniqueVector,'stable'));
rowIndex=indexInMatrix(numOfOccurrences==1);
A=A(rowIndex,:);

태그

Community Treasure Hunt

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

Start Hunting!

Translated by