필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Barbara
Barbara 2014년 8월 13일
댓글: Barbara 2014년 8월 13일
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일
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일
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일
Output = Input([true,diff(Input)~=0])

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by