If we consider the following initial vector : x= [2 3 7 4 8 5 1 6] that would be updated according to a discrete uniform permutation (reshuffling numbers from 1 to 8). And I would like to have the following condition respected:
if abs (x(i)- x(i-j))= j then S(x)=1 every time this happens
where : i=2:8 and j=1:7
As there are 28 comparisons to be made (if we consider a matrix B with i in rows and j in columns then we have a 7x7 matrix, but we only consider the upper half including the diagonal) to avoid issues related to negative index . Perhaps the indicator function could be used.
Then B(i,i-j)= 1 every time the condition is respected otherwise zero.
Finally i would sum the number of ones obtained in S(x). I tried the following code but I am really not sure this is the right way to make such comparisons within the same vector. I get an (i , j ) matrix filled with zeros and one "1" always at the same location (2,1) whatever the content of x.
x= [2 3 7 4 8 5 1 6]