I am using MATLAB. I have a question about how i can verify that the values of a matrix are being repeating, like this:
A=[ 2 3 2 3 2 3 2 3]
If
The following one-liner works if A
is a row or column vector, but not necessarily if it is a matrix (thanks to @Dan for providing a simplification in comments). I figured this would be okay since the example you provide in the question is a vector.
AUX = ~any(A(3:end) - A(1:end-2))
This vectorized solution should be a lot faster than the non-vectorized solution supplied by @Nirk (for large A
).
Depending on your application you may need to include the error trap:
if size(A, 2) < 3; error('Input matrix needs to have at least 3 columns'); end
Note, see the comments on this answer for some alternative ways of dealing with the case size(A, 2) < 3
.