MATLAB Answers

0

How to find out whether there is a repetitive element in the columns of a matrix?

Asked by IBM watson on 17 Apr 2019
Latest activity Commented on by IBM watson on 17 Apr 2019
example:
a=[ 1 2 3
4 2 1
1 4 2]
Bold ones are that what I am looking for. There is no need for imformation about their indexes. I just want to know whether there is or not.
Thank you.

  0 Comments

Sign in to comment.

Tags

2 Answers

Answer by madhan ravi
on 17 Apr 2019
 Accepted Answer

Repetitions_in_columns=true(size(a,2),1);
for k = 1:size(a,2)
Repetitions_in_columns(k)=any(sum(a(:,k)==unique(a(:,k)).')>1);
end
Repetitions_in_columns % 1 means yes 0 means no each

Answer by Stephen Cobeldick on 17 Apr 2019

"I just want to know whether there is or not."
>> any(diff(sort(a,1),1)==0,1)
ans =
1 1 0