Deleting similar rows in Matrices contained in cell
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Kye Taylor
2012-5-31
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!