Checking many matrices for identical values

1 次查看(过去 30 天)
I have approximately 30 matrices of varying dimensions (all 3xN, but the number of columns varies, the value in the first row of all of them corresponds to the actual column), similar to below
1 2 3 4 5 .. N x1 x2 x3 x4 x5 .. xN
y1 y2 y3 y4 y5 .. yN
I want to be able check what values (if any) are common to all 30 matrices (or common to only 5, 10 etc.). Even better would be if I could check if say the 'pair' (x1,y1) appeared in a column (which wouldn't necessarily be column 1) of any other matrices.
I can't even think what's the best way to start tackling this so any insight would be most appreciated!

回答(1 个)

Andrei Bobrov
Andrei Bobrov 2012-5-16
eg:
A - your data cell array (in this is case with size 1 x 5) within double array 3 x N
A = cellfun(@(x)[1:size(x,2);x],arrayfun(@(x)randi([5 10],2,randi([2,6])),1:5,'un',0),'un',0)
% solution
n2 = cellfun('size',A,2)
aa = [A{:}];
[a b c] = unique(aa(2:3,:)','rows','first');
[idx,idx] = sort(b);
nkk = accumarray(c,(1:numel(c))',[],@(x){x});
[nm,nm] = cellfun(@(x)histc(x,cumsum([0,n2])+100*eps),nkk,'un',0);
out = [num2cell(a(idx,:)');nm(idx)'];
  1 个评论
Manannan
Manannan 2012-5-16
I'm having trouble understanding what exactly the last four lines are doing. Could you please explain?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by