indexing duplicates in cell arrays

im currently attempting to locate small atomic features within a large atomic structure using matlab.
This involves, calculating interatomic distances, defining bonds etc etc which has all been done. The final piece of the puzzle is what is troubling me. The feature in question is a diamond shaped planar fragment i.e. a single atom bonded to two atoms which are in turn bonded to a 4th atom. The way i attacked this problem was by finding all atoms bonded to at least 2 others, then determing which atoms those bonds are to, then determine what atoms those are in turn bonded atom. This means i start with a single number( which identifies the atoms) which is bonded to an 1D array and that array is leads to a 2D array all of which i place into N*3 cell array (where N is the number of atoms with more than 2 bonds).
so a typical line looks like this
2 [61;85;88] [3x1 cell]
where the 3x1 cell looks like this
[2;44;85;88]
[2;19;34;44;61;74]
[2;23;61]
what i need to do now is search this 3x1 cell array (the dimention isnt fixed at 3 it can vary from 2 upto 10+) for duplicate entries which arent equal to the value in the first cell i.e. 2. Once the duplicates are found i need to also determine which of the cells there are in so i know which atom the duplicates belong too. For example in this case atom 2 is bonded to 61 and 85 which are both in turn bonded to 44, similarly 2 is bonded to 85 and 88 which are bonded to 61.
unfortunately im qutie new to matlab and coding in general so i dont know how to solve this problem. any help would be appriciated
thank you

댓글 수: 2

Sean de Wolski
Sean de Wolski 2011년 10월 10일
Can you show the output you expect for the above example please?
kieth
kieth 2011년 10월 11일
the answers should be 2 61 85 44 and 2 85 88 61 tho the order of the numbers doesnt matter as long as the sequence is the same

댓글을 달려면 로그인하십시오.

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2011년 10월 10일

0 개 추천

A_ID=2;
B=[61;85;88];
C={[2;44;85;88],[2;19;34;44;61;74],[2;23;61]};
Out=[];
B_2=nchoosek(B,2);
for k=1:size(B_2,1)
for M=1:length(C)
M_Cell=[];
if ~ismember(B_2(k,1),C{M})
continue;
else
M_Cell=C{M};
end
for N=1:length(C)
N_Cell=[];
if M==N || ~ismember(B_2(k,2),C{N})
continue
else
N_Cell=C{N};
end
Common=intersect(M_Cell,N_Cell);
Common=setdiff(Common,A_ID);
if ~isempty(Common)
Out=[Out;B_2(k,:),Common];
end
end
end
end
>> Out
Out =
61 85 44
61 88 44

댓글 수: 2

kieth
kieth 2011년 10월 11일
this method is so close, it seems to correctly identify the first set of bonds i.e. 61 85 44, however the 2nd set isnt 61 88 44, its 61 88 85
Fangjun Jiang
Fangjun Jiang 2011년 10월 11일
I can't seem to understand how your result should come out. You'll have to explain in details.

댓글을 달려면 로그인하십시오.

Daniel Shub
Daniel Shub 2011년 10월 10일

0 개 추천

Your description sounds an awful lot like a linked list to me.
It seems your current data structure is such that it is causing problems. I think if you get the structure of your data squared away, the calculation will be easier.

카테고리

도움말 센터File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

질문:

2011년 10월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by