How to eliminate subset of paths?

2 visualizaciones (últimos 30 días)
Hari
Hari el 27 de Oct. de 2016
Comentada: Hari el 31 de Oct. de 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.

Respuesta aceptada

KSSV
KSSV el 31 de Oct. de 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 comentarios
KSSV
KSSV el 31 de Oct. de 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 el 31 de Oct. de 2016
Yes. It works. Thanks alot :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by