Deleting similar rows in Matrices contained in cell

1 view (last 30 days)
If I have a set of [ 'a' 'b' 'c' 'd'],and I want different and non repetitive combinations of 2, I get matrix A. In matrix B I store the elements which are not present in Matrix A which I find using setdiff. Now, I want to divide these four elements 'a', 'b' 'c' 'd' into sets of two and that should be non repetitive. But, in the case below: ad cd is repeating as it is similar to cd ab, similarly, ac bd is same as bd ac.
I have two matrices in a cell: A = [ ab; ac; ad; bc; bd; cd ] and B = [cd; bd; bc; ad; ac; ab ]; So, is there any function in MATLAB which can help me eliminate repetitive partition cases? I looked into unique function but that did not help.

Answers (1)

Kye Taylor
Kye Taylor on 31 May 2012
If I understand your objective, try the following
arrayOfElements = ['a','b','c','d']; % your initial array
indicesOfUniquePairs = nchoosek(1:length(arrayOfElements),2);
arrayOfUniquePairs = arrayOfElements(indicesOfUniquePairs);
It's a beautiful thing.
  1 Comment
Rinachi Garg
Rinachi Garg on 1 Jun 2012
nchoosek is really cool.
Actually my question was: As can be seen in the above matrix :
ab(from Matrix A) corresponds to cd in Matrix B. and cd from Matrix A corresponds to ab in Matrix B. So I consider that this case is being repeated so I want to delete such cases and get the final output:
A = [ab; ac; ad] and B = [cd; bd; bc];
There is always an option of writing a tedious code. But, I was looking for a way which can do it faster. Because here I am giving simple examples but I may have large number of arrays to compare with many more elements.

Sign in to comment.

Categories

Find more on Numeric Types in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!