필터 지우기
필터 지우기

Count unique values in an array

조회 수: 6 (최근 30일)
Ana
Ana 2014년 3월 29일
댓글: Ana 2014년 3월 30일
Hello,
I have the following set of data
I need to count how many times the values in column 3 appear. So, for instance: SABC appears 4 times. BTFG appears 20 times. GCBK appears 7 times and so on.
Afterwards I would want to erase the rows for the variables that appear less than 100 times. Is there an efficient way to do this? I'm new at matlab. Thank you so much in advance.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 29일
편집: Azzi Abdelmalek 2014년 3월 29일
If M is your cell array Try this,
c3=M(:,3)
[ii,jj,kk]=unique(c3)
f=histc(kk,1:numel(jj)); % Frequencies corresponding to ii
idx=f<100
idx1=ismember(c3,ii(idx))
M(idx1,:)=[]
  댓글 수: 1
Ana
Ana 2014년 3월 30일
Thank you, it works perfectly!!

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2014년 3월 29일
hint: how many outputs can unique() have?

카테고리

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