M is a matrix 4x2000000 composed of several submatrix Ai such that Ai(1:3,j) is the same vector for j = 1,...,size(Ai,2
M
4x2000000
Ai
Ai(1:3,j)
j = 1,...,size(Ai,2
One approach -
[~,~,idx] = unique(M(1:3,:)','rows') %//' valid = ismember(M(4,:),V) valid_idx = accumarray(idx(valid),M(4,valid).',[],@(x) ... numel(unique(x)))>=numel(V) %//' out = M(:,ismember(idx,find(valid_idx)))