How Can I count the ascending runs in array ?

조회 수: 1 (최근 30일)
Willim
Willim 2019년 2월 18일
댓글: Willim 2019년 2월 18일
if I have an array such as
x=[1 2 3 2 1 2 4 5]
I would generate a binary array for binary search
binaryarray= [1 1 1 0 0 1 1 1]
in binaryarry i would sign 1 along with ascending runs while 0 along with descending runs.
  댓글 수: 2
KSSV
KSSV 2019년 2월 18일
diff shall be useful..read about it.
Willim
Willim 2019년 2월 18일
I used it
v=diff(x)
v(v>=0)=1
v(v<0)=0
but it give me wrong result for larger x

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

답변 (1개)

Stephen23
Stephen23 2019년 2월 18일
편집: Stephen23 2019년 2월 18일
As KSSV wrote, you might find diff useful:
>> y = y([1,1:end])
y =
1 1 1 0 0 1 1 1

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by