Remove consecutive values from vector

조회 수: 15 (최근 30일)
Rose
Rose 2019년 12월 2일
댓글: Rose 2019년 12월 3일
Hey Guys,
I have this vector with increasing values (always positive) up till a certain point, after which it returns to zero again (straight line), and starts increasing again. A so called "saw" pattern. Now I am trying to determine the first indice in the vector which has a value above a certain threshold, but when I do so I get a vector with all of values above threshold.
It would be fixed if I could manage to remove the consecutive indices, and only store the first indice. I tried the following code, but this actually returns the last value of the consecutive numbers. (output is [3,7,12])
Any clue on how to change this to [1,7,10] ?
a = [1;2;3;7;10;11;12]
x = [diff(a')~=1,true];
a(x)
  댓글 수: 2
Image Analyst
Image Analyst 2019년 12월 2일
Huh? How is "a" a sawtooth pattern?
0000 Screenshot.png
Rose
Rose 2019년 12월 3일
This vector I used just as an example to illustrate what I tried to achieve...

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

채택된 답변

Ruger28
Ruger28 2019년 12월 2일
a = [1;2;3;7;10;11;12];
x = diff(a);
y = vertcat(true,x~=1); % shift index down to grab first number
a(y);
a = 1
7
10

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by