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

4 views (last 30 days)
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

Answers (1)

Udit Gupta
Udit Gupta on 29 May 2014
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 Comments
hassan
hassan on 29 May 2014
Edited: hassan on 29 May 2014
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 on 29 May 2014
I am confused by you explanation but can you sort both the arrays into temporary variables before using set operations.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!