Help finding duplicate values in an array of matrices?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Azzi Abdelmalek
2014년 8월 7일
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
Azzi Abdelmalek
2014년 8월 7일
You can check the result, or give more details about what you want. You can illustrate with a short example, like I did
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!