Determining unique abbreviations in a dataset

조회 수: 2 (최근 30일)
Joseph Williams
Joseph Williams 2013년 2월 8일
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
Walter Roberson
Walter Roberson 2013년 2월 8일
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 2013년 2월 8일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2013년 2월 8일
size(unique(x, 'rows'),1)

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 8일
s=['AK';'AZ';'CA';'CA';'IL';'ID';'ID';'MS';'NH']
out=unique(s,'rows')

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by