I have two vectors in MATLAB, A and B. B contains some indices (1 to end). I have a random index, R (within the range of the vector indices). I want to write a function (or statement) to choose A[z], where z is the most nearest number (i.e index) to R that is not included in B.
Example:
A = [2 3 6 1 9 7 4 5 8]
B = [3 4 5 6 7 8]
R = 5
The function must return 3, because the most nearest index is 2, because 5-2<9-5 and 2 is not in B, so A[2] = 3;
Thanks
Please note that setdiff and setxor functions sort the result.
The same Example in the question:
Thank you for your ideas.