How to find overlapping between multiple cell array in a row?

4 次查看(过去 30 天)
I have list of cell array (in row) as follow:
'1,2' '1,2,3' '1,4' '2,3' '4,5,2' '3,2,5,4' '2,4,1,5' '4,5'
I want to find overlapping cell arrays from the row and delete them. I am going to have huge list of these row cell arrays, so I need a efficient way to find the overlapping.
there are 2 Overlapping procedures:
1 for existing sequence and the other for flip of sequence
for existing sequence means:
Ex. '1,2' has overlapping with '1,2,3' , so '1,2' has to be removed '2,3' has overlapping with '1,2,3' also, so '2,3' will be removed from the list also.
for flip of sequence means , if searching for '1,4, then it needs to serach for '4,1' also because '1,4' = '4,1'
'1,4' has over lapping with '2,4,1,5' so '1,4' also removed
'4,5,2' has overlap with '3,2,5,4', because flip of '4,5,2'='2,5,4' which has overlapping with '3,2,5,4'
if someone can help me with these problem I appreciate.
Regards

回答(1 个)

Udit Gupta
Udit Gupta 2014-5-29
Matlab allows set operations. I can think of doing it a few ways using "ismember" or "union" methods. Please see
Let us know if you need more help.
  2 个评论
hassan
hassan 2014-5-29
编辑:hassan 2014-5-29
ismember, intersect or union wont work because it does not consider flip overlapping problem.
I have tried to make a search individually for each cell array with others. First creating original cell and flip one. if there are similar cell array to original or flip, then it is removed. but when size of cell array goes beyond 2, story changes and I get wrong results.
between '1,2' and '1,2,3':
for '1,2' it is also '2,1' for '1,2,3' it is '1,2' and '2,3' or '2,1' and '3,2'
if my first '1,2' is part of '1,2,3' then it is removed.
For '1,2' search '1,2,3' search similarity with'1,2' '2,1' '2,3' '3,2'
For '1,2' take'1,4' search similarity with'1,4' '4,1'
For '1,2' search '2,3' search similarity with '2,3' '3,2'
For '1,2' search '4,5,2' search similarity with '4,5, ,5,4, '5,2' '2,5'
For '1,2' search '3,2,5,4' search similarity with'3,2' '2,3' '2,5' '5,2''5,4' '4,5'
For '1,2' search '2,4,1,5' search similarity with'2,4' '4,2' '4,1' '1,4' '1,5' '5,1'
For '1,2' search '4,5 search similarity with'4,5' '5,4'
Then '1,2' is removed
Again start again for next cell array (for '1,4')
Then: between '1,4' search '1,2' search similarity with'1,2' '2,1'
Then: between '1,4' search '1,2,3' search similarity with'1,2' '2,1' '2,3' '3,2'
Then: between '1,4' search '2,3' search similarity with '2,3' '3,2'
Then: between '1,4' search '4,5,2'
Then: between '1,4' search '3,2,5,4' search similarity with'3,2' '2,3' '2,5' '5,2' '5,4' '4,5'
Then: between '1,4' search '2,4,1,5' search similarity with'2,4' '4,1' '1,4' '4,2' '1,5' '5,1'
Then: between '1,4' search '4,5' search similarity with'4,5' '5,4'
'1,4' is also is removed
and so on for '1,2,3' and '2,3' and '4,5,2' and '3,2,5,4' and '4,5' etc....
Final remaining out of: '1,2' '1,2,3' '1,4' '2,3' '4,5,2' '3,2,5,4' '2,4,1,5' '4,5'
'1,2' is removed because of '1,2,3'
'1,2,3' is remaining
'1,4' is removed because of '2,4,1,5'
'2,4,1,5' is remaining
'2,3' is removed because of '1,2,3'
'4,5,2' is remaining
'3,2,5,4' is remaining
'4,5'is removed because of '3,2,5,4'
final result is
'1,2,3' '4,5,2' '3,2,5,4' '2,4,1,5'
Is there any suggestion?
Udit Gupta
Udit Gupta 2014-5-29
I am confused by you explanation but can you sort both the arrays into temporary variables before using set operations.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by