Help finding duplicate values in an array of matrices?

4 views (last 30 days)
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 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 7 Aug 2014
Can you explain where will you store the duplicate coordinates?
cocopuffs
cocopuffs on 7 Aug 2014
Hi Azzi, I just posted the code I attempted. does that answer your question?

Sign in to comment.

Answers (1)

Azzi Abdelmalek
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 Comments
cocopuffs
cocopuffs on 7 Aug 2014
Thank you fo rthe response. I am not too sure how this is supposed to help. Have you taken a look at the code?
Azzi Abdelmalek
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

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!