필터 지우기
필터 지우기

How to remove non consecutive values from a vector?

조회 수: 5 (최근 30일)
GEORGIOS BEKAS
GEORGIOS BEKAS 2018년 2월 15일
댓글: GEORGIOS BEKAS 2018년 2월 15일
I have the following vector that represents how many times consecutive values appear in a row by using the following code:
x = [5 3 3 1 0 9 9 4 4 4 4 5 1 2 2];
y=[]
for i = 1:length(x)
a = length(find(x(1:i)==x(i)));
y=[y,a];
end
and I want a code to remove the 2 2 subelements from the resultant y matrix.
y= [1 1 2 1 1 1 2 1 2 3 4 2 2 1 2]
  댓글 수: 2
Akira Agata
Akira Agata 2018년 2월 15일
The last sentence of your question is not clear for me. Could you tell us more detail on it and provide what the final output of your example looks like?
GEORGIOS BEKAS
GEORGIOS BEKAS 2018년 2월 15일
y= [1 1 2 1 1 1 2 1 2 3 4 1 1 1 2]

댓글을 달려면 로그인하십시오.

채택된 답변

Birdman
Birdman 2018년 2월 15일
y= [1 1 2 1 1 1 2 1 2 3 4 2 2 1 2]
idx=find(abs(diff(y))==2)+1;
y(idx:idx+1)=1
  댓글 수: 1
GEORGIOS BEKAS
GEORGIOS BEKAS 2018년 2월 15일
correct. but aby non consecutive has the relationship: idx=find(abs(diff(y))>=2)+1; y(idx:idx+1)=1

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by