finding only unique values
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
the cyclist
am 22 Aug. 2013
Bearbeitet: the cyclist
am 22 Aug. 2013
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)
Weitere Antworten (2)
David Sanchez
am 22 Aug. 2013
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
0 Kommentare
Azzi Abdelmalek
am 22 Aug. 2013
[ii,jj]=sort(x);
out=sort(jj(strfind(logical([1 diff(ii) 1]),[true,true])))
0 Kommentare
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!