Effacer les filtres
Effacer les filtres

Accumulating Unique Set Values

2 vues (au cours des 30 derniers jours)
MByk
MByk le 20 Fév 2019
Modifié(e) : MByk le 20 Fév 2019
I have 10 sets (each set includes 1s and 0s: 1 means element selected) and trying to find the unique sets and store its element indices. But when there is only one unique set following code gives error. How can I fix it? Thanks for the help.
[Rw,Cl] = find(unique(FSet,'rows','stable'));
UnqFS = accumarray(Rw,Cl,[], @(f) {sort(f).'});
celldisp(UnqFS)
  2 commentaires
Jos (10584)
Jos (10584) le 20 Fév 2019
What is Fset? A 10-by-N array?
Perhaps you can give a (small) example of the input and expected output?
MByk
MByk le 20 Fév 2019
Modifié(e) : MByk le 20 Fév 2019
Yes, it is 10 by N binary array. But i think i solved the problem like this.
[Rw,Cl] = find(unique(FSet,'rows','stable'));
if iscolumn(Rw)
UFS = accumarray(Rw,Cl,[], @(f) {sort(f).'});
celldisp(UFS)
end

Connectez-vous pour commenter.

Réponse acceptée

Jos (10584)
Jos (10584) le 20 Fév 2019
My suggestion: first find the unique rows of Fset, and then get the column indices for each row
FSet = randi(2,10,3) -1 % example
UFS = unique(FSet,'rows','stable')
UnqFS = arrayfun(@(r) find(UFS(r,:)), 1:size(UFS,1), 'un',0)
celldisp(UnqFS)
  1 commentaire
MByk
MByk le 20 Fév 2019
Thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time 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