MATLAB: Logical vector equality

vector equality

Often I run into a situation where I need to determine if two vectors are equal and do something if they are. However, vec1==vec2 gives me a vector – not a logical 0 or 1. So I have to mess with that and it seems that Matlab should be able to tell me if two vectors or even structures are equal. However, I am not smart enough to figure how to make it do that without writing extra code every time it arises.
My question is how to I get a 0 or 1 result from v1==v2 when they are vectors?

Best Answer

all(vec1==vec2)
and if you want to ignore the difference between column and row vectors do
all(vec1(:)==vec2(:))
There's also this way to compare
isequal(vec1,vec2)
With the isequal you don't have the problem with the dimensions mismatch like you have with the case vec1==vec2