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

3 次查看(过去 30 天)
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