Q:

Checking equality of vector elements

Say we have the following vectors in matlab:
v1=[2 2 2 2 2 2 2]

v2=[2 2 2 2 3 2 2]

How can we check that all the elements in each vector are equal or not?
EDIT (NOTE)
I'm not asking about comparing the two vectors to each other, but the elements inside each vector together. For example, v1 has all its elements equal to each other, while v2 not.
Thanks.

A:

length(unique(v1)) == 1

>> 1

length(unique(v2)) == 1

>> 0

To exclude a number that I don't want to include here, e.g 0 in this example:
v3=[2 2 2 2 2 2 2 0]
length(unique(v3(v3 ~= 0))) == 1
>> 1

