How can I delete repeated elements? (not unique!)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I'd like to delete repeated elements, but keep it in this way:
Input = [2 2 3 3 4 2 2 5 3 3]
Output = [2 3 4 2 5 3]
With unique, some of these elements disappear. Does exist an other function?
Thx
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (2)
Joakim Magnusson
am 13 Aug. 2014
I don't know such a function, but try this:
Output = Input;
0 = 1;
while i < size(Output,2)
if Output(i) == Output(i+1)
Output(i+1) = [];
else
i = i+1;
end
end
0 Kommentare
Andrei Bobrov
am 13 Aug. 2014
Bearbeitet: Andrei Bobrov
am 13 Aug. 2014
Output = Input([true,diff(Input)~=0])
0 Kommentare
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots 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!