How can I delete repeated elements? (not unique!)

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

 Akzeptierte Antwort

Iain
Iain am 13 Aug. 2014

0 Stimmen

output = [input(1) input(find(diff(input))+1)]

1 Kommentar

thank you :) based on what you've sent it works with this one:
output = input(find(diff(input)))

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Joakim Magnusson
Joakim Magnusson am 13 Aug. 2014

0 Stimmen

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
Andrei Bobrov
Andrei Bobrov am 13 Aug. 2014
Bearbeitet: Andrei Bobrov am 13 Aug. 2014

0 Stimmen

Output = Input([true,diff(Input)~=0])

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 13 Aug. 2014

Kommentiert:

am 13 Aug. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by