unique set from file

2 vues (au cours des 30 derniers jours)
Sanjana Sankar
Sanjana Sankar le 29 Juil 2019
Commenté : Sanjana Sankar le 29 Juil 2019
I have a .mat file with 14994x31 cells with random alphabets in the cells. I need to find the unique set. I know it is going to be the set of all alphabets only. But I want to find exactly which alphabets are present (if not all). Is the anyway to find out the unique set for the entire file and not just row by row?
  2 commentaires
Adam Danz
Adam Danz le 29 Juil 2019
Could you give us an example of the cell array?
Sanjana Sankar
Sanjana Sankar le 29 Juil 2019
'!' 'a:' 'l' 't' '@' [] []
'?' 'a:' 'l' 't' '@' 's' 't'
'/' 'a' 'b' 'a' 'n' 'd' 'A~'
3 different rows

Connectez-vous pour commenter.

Réponse acceptée

Adam Danz
Adam Danz le 29 Juil 2019
Modifié(e) : Adam Danz le 29 Juil 2019
c = {'!' 'a:' 'l' 't' '@' [] []
'?' 'a:' 'l' 't' '@' 's' 't'
'/' 'a' 'b' 'a' 'n' 'd' 'A~'};
cUnq = unique(c(cellfun(@ischar,c)));
Result
cUnq =
13×1 cell array
{'!' }
{'/' }
{'?' }
{'@' }
{'A~'}
{'a' }
{'a:'}
{'b' }
{'d' }
{'l' }
{'n' }
{'s' }
{'t' }
If you want to keep the unique elements in their original order,
cUnq = unique(c(cellfun(@ischar,c)),'stable');

Plus de réponses (1)

Joel Handy
Joel Handy le 29 Juil 2019
Modifié(e) : Joel Handy le 29 Juil 2019
c = {'!' 'a:' 'l' 't' '@' [] []
'?' 'a:' 'l' 't' '@' 's' 't'
'/' 'a' 'b' 'a' 'n' 'd' 'A~'};
for rowIdx = 1:size(c,1)
cString(rowIdx) = string([c{rowIdx,:}])
end
uniqueSets = unique(cString)
  1 commentaire
Sanjana Sankar
Sanjana Sankar le 29 Juil 2019
Thank you. This also works!!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by