How to eliminate subset of paths?

1 次查看(过去 30 天)
Hari
Hari 2016-10-27
评论: Hari 2016-10-31
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.

采纳的回答

KSSV
KSSV 2016-10-31
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 个评论
KSSV
KSSV 2016-10-31
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 2016-10-31
Yes. It works. Thanks alot :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Denoising and Compression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by