MATLAB: Finding location of change of signs of a matrix’s elements

findgraphmatrix

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.

Best Answer

find(diff(sign(A)))+1
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.