How Can I count the ascending runs in array ?

2 Ansichten (letzte 30 Tage)
Willim
Willim am 18 Feb. 2019
Kommentiert: Willim am 18 Feb. 2019
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 Kommentare
KSSV
KSSV am 18 Feb. 2019
diff shall be useful..read about it.
Willim
Willim am 18 Feb. 2019
I used it
v=diff(x)
v(v>=0)=1
v(v<0)=0
but it give me wrong result for larger x

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Stephen23
Stephen23 am 18 Feb. 2019
Bearbeitet: Stephen23 am 18 Feb. 2019
As KSSV wrote, you might find diff useful:
>> y = y([1,1:end])
y =
1 1 1 0 0 1 1 1

Kategorien

Mehr zu Software Development Tools finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by