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

조회 수: 3 (최근 30일)
hassan
hassan 2014년 5월 29일
편집: hassan 2014년 5월 29일
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