How to get rid of repeating values inside an array
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rokki
am 19 Sep. 2017
Bearbeitet: Andrei Bobrov
am 21 Sep. 2017
I have a matrix
a=[1 2 3 3 4 4 5];
I want to get rid of values 3 and 4 as they are repeating so that the output becomes
b=[1 2 5]
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Andrei Bobrov
am 19 Sep. 2017
Bearbeitet: Andrei Bobrov
am 21 Sep. 2017
v = unique(a);
b = v(histcounts(a,[v(:);v(end)+eps]) == 1);
or
v = unique(a);
b = v(histc(a,v) == 1);
or
aa = sort(a);
t = diff(aa);
b = aa([1 t] & [t 1]);
3 Kommentare
José-Luis
am 19 Sep. 2017
histcounts() was introduced with R2014b. You don't need it though. unique() is enough. Andrei was giving you two alternatives.
Siehe auch
Kategorien
Mehr zu NaNs 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!