Effacer les filtres
Effacer les filtres

Deleting similar rows in Matrices contained in cell

2 vues (au cours des 30 derniers jours)
Rinachi Garg
Rinachi Garg le 31 Mai 2012
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.

Réponses (1)

Kye Taylor
Kye Taylor le 31 Mai 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 commentaire
Rinachi Garg
Rinachi Garg le 1 Juin 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Numeric Types dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by