Hi there, I have a 6 million x 1 array of prices. I want to change it so that it is +1 if P+1 > P, -1 if P-1 <P and 0 if P+1=P

2 个评论

Mate 2u
Mate 2u 2012-5-4
Additionally would prefer if algorithm is quick.
Daniel Shub
Daniel Shub 2012-5-4
What happens if P < P+1 and P > P-1?

请先登录,再进行评论。

 采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-5-4

1 个投票

sign(diff(P));

3 个评论

Mate 2u
Mate 2u 2012-5-4
What happens if the diff is 0?
Andrei Bobrov
Andrei Bobrov 2012-5-4
hence P(ii) == P(ii + 1)
Daniel Shub
Daniel Shub 2012-5-4
@Mate, the documentation for sign clearly states that sign(0) is 0.

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Language Fundamentals 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by