Two vectors different from each other at least at two points

1 view (last 30 days)
I want to compare two vectors and check whether they are different at least at two coordinates.

Accepted Answer

jonas
jonas on 6 Oct 2018
Edited: jonas on 6 Oct 2018
sum(abs(V1-V2)~=0)>=2
Will output 1 if they differ at two or more indices. You may want to set a tolerance if they are floating point numbers.
tol=0.01
sum(abs(V1-V2)>tol)>=2
  2 Comments
jonas
jonas on 7 Oct 2018
Edited: jonas on 7 Oct 2018
If you remove the sum, then you will be left with a logical array where 1 represent indices with differing values. You can for example use
find(abs(V1-V2)>tol)

Sign in to comment.

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!