MATLAB: How many times does the vector change sign

vector

I have this vector signal=[0.6, 0.2, −0.1, 0.1, 0.3, 0.3, −0.1, −0.8, −0.9, −0.5, 0.4, 1.0, 0.8, 0.2, −0.4, −0.5, −0.1, 0.1, −0.1, −0.5]
As you can se the signal changes sign 7 times
How can I make a easy function that tell me that? Also with others vector?

Best Answer

As long as there are no 0's, you could use something like this:
result = numel(find(diff(sign(signal))));
If there are 0's, then you would need to tell us how to handle them.