How Can I count the ascending runs in array ?

2 visualizaciones (últimos 30 días)
Willim
Willim el 18 de Feb. de 2019
Comentada: Willim el 18 de Feb. de 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 comentarios
KSSV
KSSV el 18 de Feb. de 2019
diff shall be useful..read about it.
Willim
Willim el 18 de Feb. de 2019
I used it
v=diff(x)
v(v>=0)=1
v(v<0)=0
but it give me wrong result for larger x

Iniciar sesión para comentar.

Respuestas (1)

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

Categorías

Más información sobre Software Development Tools en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by