필터 지우기
필터 지우기

Help finding duplicate values in an array of matrices?

조회 수: 6 (최근 30일)
cocopuffs
cocopuffs 2014년 8월 7일
댓글: Azzi Abdelmalek 2014년 8월 7일
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
Azzi Abdelmalek
Azzi Abdelmalek 2014년 8월 7일
Can you explain where will you store the duplicate coordinates?
cocopuffs
cocopuffs 2014년 8월 7일
Hi Azzi, I just posted the code I attempted. does that answer your question?

댓글을 달려면 로그인하십시오.

답변 (1개)

Azzi Abdelmalek
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
cocopuffs
cocopuffs 2014년 8월 7일
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 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by