Checking many matrices for identical values

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!

Answers (1)

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 Comment

I'm having trouble understanding what exactly the last four lines are doing. Could you please explain?

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Asked:

on 16 May 2012

Community Treasure Hunt

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

Start Hunting!