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

 採用された回答

Iain
Iain 2014 年 8 月 13 日

0 投票

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

1 件のコメント

Barbara
Barbara 2014 年 8 月 13 日
thank you :) based on what you've sent it works with this one:
output = input(find(diff(input)))

サインインしてコメントする。

その他の回答 (2 件)

Joakim Magnusson
Joakim Magnusson 2014 年 8 月 13 日

0 投票

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 2014 年 8 月 13 日
編集済み: Andrei Bobrov 2014 年 8 月 13 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2014 年 8 月 13 日

コメント済み:

2014 年 8 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by