How Can I count the ascending runs in array ?

2 vues (au cours des 30 derniers jours)
Willim
Willim le 18 Fév 2019
Commenté : Willim le 18 Fév 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 commentaires
KSSV
KSSV le 18 Fév 2019
diff shall be useful..read about it.
Willim
Willim le 18 Fév 2019
I used it
v=diff(x)
v(v>=0)=1
v(v<0)=0
but it give me wrong result for larger x

Connectez-vous pour commenter.

Réponses (1)

Stephen23
Stephen23 le 18 Fév 2019
Modifié(e) : Stephen23 le 18 Fév 2019
As KSSV wrote, you might find diff useful:
>> y = y([1,1:end])
y =
1 1 1 0 0 1 1 1

Catégories

En savoir plus sur Software Development Tools dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by