how can we compare two columns for a particular value of another column?

조회 수: 3 (최근 30일)
Rahul kumar
Rahul kumar 2021년 6월 10일
편집: Matt J 2021년 6월 10일
i have n by 7 columns of data,
for a particular value in a column 1(ranges from 1 to 60),i want to check if the values in column 4 and 5 are repeating or not,also i want to check if same set of values interchanged and delete such repeated values.
could anyone please help me in getting this done.
thanks in advance.

채택된 답변

Matt J
Matt J 2021년 6월 10일
편집: Matt J 2021년 6월 10일
Say A is the matrix of values.
[~,uniqueRows]=unique(A(:,[1,4,5]),'rows')
This will tell you which rows can be kept so as to obtain unique combinations of values in columns 1,4, and 5. The other rows can be discarded. Is that not what you want?
  댓글 수: 2
Rahul kumar
Rahul kumar 2021년 6월 10일
yes, thanks that answered my question but i also would like to delete the interchanged values,is that possble??
for example: A=[a b;b d;d b;a b]
in the matrix A the 2nd and 3rd row have the same pair of values but interchanged i would want to consider them as duplicates.Can those be deleted??
Matt J
Matt J 2021년 6월 10일
편집: Matt J 2021년 6월 10일
Just pre-sort the 4th and 5th column.
B=[ A(:,1) , sort(A(:,4:5),2) ];
[~,uniqueRows]=unique(B,'rows')

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

추가 답변 (0개)

카테고리

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