I have two matrices in this form:
ind=
1
1
1
1
2
2
2
2
2
3
3
type =
A
A
B
A
A
B
A
B
A
B
A
I want to be able to identify pairs of a specific kind i.e. A-B and B-A but not A-A. I have been able to do this using IF statements in this form:
if strcmp(type(m),'A') == 1 && strcmp(type(m+1),'B') == 1 && ind(m) == ind(m+1)
And so forth.
As hinted to within this IF statement, I need to be able to calculate how many valid pairs there are per index.
For example, the first four types AABA
belong to index '1' because index '1' has a length of 4 as specified in ind
. Here there are two valid pairs A-B and B-A. A-A is not a valid pair.
The desired output for the full above example would be:
2
4
1
Is there a quick and easy way to accomplish this?
EDIT:
If the types were expanded to include 'C' - and the system needs to detect non-unique pairs i.e. A-B, B-A but also B-B (but nothing containing C) - could this be done? Is there a way to specify which pairs are being counted each time?