How Can I count the ascending runs in array ?

1 次查看(过去 30 天)
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 个评论
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 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by