Determining unique abbreviations in a dataset

2 views (last 30 days)
I have a dataset in the char format. For example
RPG
RTS
RTS
GBA
PSP
PS3
XBX
TBS
FFS
would be 8.
Is there a function I can use to return the number of unique abbreviations in the dataset. I have tried length(unique(x)), but that did not return the correct answer.
  2 Comments
Walter Roberson
Walter Roberson on 8 Feb 2013
Watch out -- length() of a 1x2 vector of char would be 2 whereas you would be wanting 1 in the case there was only a single unique state in the list. size() is better for this.
Joseph Williams
Joseph Williams on 8 Feb 2013
Works like a charm. Thanks! I was thinking that there might be issues with keeping it in char format after I tried sorting them like that, so I ended up converting them to cells in the end. It seems easier to manage with the rest of the data anyhow.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 8 Feb 2013
size(unique(x, 'rows'),1)

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 8 Feb 2013
s=['AK';'AZ';'CA';'CA';'IL';'ID';'ID';'MS';'NH']
out=unique(s,'rows')

Categories

Find more on Shifting and Sorting Matrices 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!