フィルターのクリア

Help finding duplicate values in an array of matrices?

9 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by