MATLAB Answers

Finding location of change of signs of a matrix's elements

66 views (last 30 days)
Hi everbody, I have a matrix like this:
A=[0 0 0 0.33 0.33 0.33 0 0 0 -0.33 -0.33 -0.33 0 0 0];
How can i find location of change of signs? I get an error while using find and diff command. I think, i have made a mistake because of the < and > symbols. May you help me? Thanks.

Accepted Answer

Walter Roberson
Walter Roberson on 18 Feb 2017
to return the locations of the beginning of the new sign.
Note that this includes changing to 0, as 0 has a different sign than positive numbers or negative numbers.
MA-Winlab on 7 Apr 2019
I figured out how to do that (in my case, the vector of 0s and 1s has an even number):
OpenClose = find(diff(sign(A))) + 1;
OneToZero = OpenClose(1:2:end)
ZeroToOne = OpenClose(2:2:end)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by