How to eliminate subset of paths?

2 vues (au cours des 30 derniers jours)
Hari
Hari le 27 Oct 2016
Commenté : Hari le 31 Oct 2016
I have a cell array of paths stored as a variable:
[1,2,3,6,8,10]
[1,2,4,6,8,10]
[1,2,3,6,8,10,11]
[1,2,4,6,8,10,11]
[1,2,4,12]
[1,2,3,6,8,10,13]
[1,2,3,6,8,10,11,13]
[1,2,3,6,8,10,14]
[1,2,4,6,8,10,14]
[1,2,3,6,15]
[1,2,3,6,8,15]
[2,1]
[2,3]
[2,4]
[2,5]
[2,4,5]
[2,3,6]
Is there a way to remove those paths which are subsets of other paths? For eg: In this case [1,2,3,6,8,10] is a subset of [1,2,3,6,8,10,11] and can hence be removed. Similarly [1,2,4,6,8,10] can be removed. But [1,2,3,6,15] is not a subset of [1,2,3,6,8,15]. So the matlab functions like 'ismember' cannot be used. The end result should be:
[1,2,4,6,8,10,11]
[1,2,4,12]
[1,2,3,6,8,10,13]
[1,2,3,6,8,10,11,13]
[1,2,3,6,8,10,14]
[1,2,4,6,8,10,14]
[1,2,3,6,15]
[1,2,3,6,8,15]
[2,1]
[2,5]
[2,4,5]
[2,3,6]
Thank you for your time and help.

Réponse acceptée

KSSV
KSSV le 31 Oct 2016
p = {[1,2,3,6,8,10]
[1,2,4,6,8,10]
[1,2,3,6,8,10,11]
[1,2,4,6,8,10,11]
[1,2,4,12]
[1,2,3,6,8,10,13]
[1,2,3,6,8,10,11,13]
[1,2,3,6,8,10,14]
[1,2,4,6,8,10,14]
[1,2,3,6,15]
[1,2,3,6,8,15]
[2,1]
[2,3]
[2,4]
[2,5]
[2,4,5]
[2,3,6]};
%
k = [] ;
for i = 1:length(p)
for j = 1:length(p)
if i ~= j
if all(ismember(p{i},p{j})) ;
% p(i) = [] ;
k = [k i];
break
end
end
end
end
pos = 1:length(p) ;
idx = setdiff(pos,k) ;
iwant = p(idx) ;
  7 commentaires
KSSV
KSSV le 31 Oct 2016
This shall work:
k = [] ;
for i = 1:length(p)
for j = 1:length(p)
if i ~= j
[temp1,temp2] = (ismember(p{i},p{j})) ;
if diff(temp2)==1
k = [k i];
break
end
end
end
end
pos = 1:length(p) ;
idx = setdiff(pos,k) ;
iwant = p(idx) ;
Note that [2,3,6] is there in the first path. So this is not recognized. It should be eliminated right?
Hari
Hari le 31 Oct 2016
Yes. It works. Thanks alot :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by