# Help finding duplicate values in an array of matrices?

10 views (last 30 days)
cocopuffs on 7 Aug 2014
Commented: Azzi Abdelmalek on 7 Aug 2014
Hi everyone. Here is my issue: I have an array of 100 elements. Lets call the array 'numbers'. Each element in 'numbers' is a matrix of size NX2 (each matrix element is a list of coordinates).
I want to go through each pair of coordinates in the matrices one at a time, and compare it to ALL the other coordinates in the array. If these coordinates do match up, I want to store the duplicate coordinates in a vector.
For example: lets take numbers{1}(1,:) and check it across every single value in the array to see if the number is duplicate. If the number IS repeated, I want to store that number into a matrix. Then I want to go to the next value, numbers{1}(2,:), then numbers{1}(3,:), all the way down to numbers{100}(20,:).
I was wondering if I could please have some help with this. It seems easy but I can't seem to figure it out:
Below is the code I attempted but it doesnt work properly and not sure why.
n = numel(numbers);
duplicatecoordinates = [];
locationofduplication = [];
for i = 1:n
a = size(numbers{i},1);
for j = 1:a
c = numbers{i}(a,:);
for k = 1:n
if k ~= i
b = size(numbers{k},1);
for l = 1:b
check = numbers{k}(l,:);
if sum(eq(c,check)) == 2
locationofduplication = [locationofduplication;i,a,k,l];
duplicatecoordinates = [duplicatecoordinates, check];
end
end
end
end
end
end
Thank you so much
##### 2 CommentsShowHide 1 older comment
cocopuffs on 7 Aug 2014
Hi Azzi, I just posted the code I attempted. does that answer your question?

Azzi Abdelmalek on 7 Aug 2014
Maybe you want this
A={[1 2;1 2;0 4;7 8 ;1 2;7 8],[0 1;0 2;1 4;1 4;0 2;0 2]}
out=cellfun(@(x) unique(x,'rows'),A,'un',0)
##### 2 CommentsShowHide 1 older comment
Azzi Abdelmalek on 7 Aug 2014
You can check the result, or give more details about what you want. You can illustrate with a short example, like I did