finding only unique values

조회 수: 3 (최근 30일)
Bernard
Bernard 2013년 8월 22일
Suppose you have a column vector, the values are integers(in order) but some of them are repeated, e.g. it could be [1,1,1,1,2,3,3,4,5,5,5,5,5] I want to find the indices of unique values e.g. the index of 2 and 4 in the aforementioned example. the unique function in matlab returns on top of truly unique the first value of any nonunique value, so it would return the index of the first 1, the first 3 and first 5 but I don't want those

채택된 답변

the cyclist
the cyclist 2013년 8월 22일
편집: the cyclist 2013년 8월 22일
Maybe call these the "singleton" values. Here's one way:
x = [1,1,1,1,2,3,3,4,5,5,5,5,5];
unique_x = unique(x);
count_x = hist(x,unique_x);
singleton_x = unique_x(count_x==1)
  댓글 수: 1
Bernard
Bernard 2013년 8월 22일
brilliant this saved me time thanks

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

추가 답변 (2개)

David Sanchez
David Sanchez 2013년 8월 22일
a=[1,1,1,1,2,3,3,4,5,5,5,5,5];
x = unique(a)
y = histc(a,x)==1;
lonely_values = find ( y == 1 )
or:
lonely_values = find ( (histc(a,unique(a))==1) == 1 )
lonely_values =
2 4

Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 22일
[ii,jj]=sort(x);
out=sort(jj(strfind(logical([1 diff(ii) 1]),[true,true])))

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by