Imagine I have the following vectors:
A = [ 1 5 9 12 16] B = [ 1 4 ]
Now I am looking for an offset, that makes B an subset of A. In this example it would be 8, because B+8 gives numbers that are included in A:
A = [ 1 5 9 12 16] // same as before B = [ 9 12 ] // offset added: 1+8=9 and 4+8=12
Now I have one additional constraint for that: If there is no offset, that can map all numbers of a vector to those of A, than find the number that matches most of the numbers of a vector to those of A:
A = [ 1 5 9 12 16] // same as before C = [ 1 3 4 ]
The solution again would be 8, because this would map 1 and 4 to 9 and 12. 3 gets mapped to 11, which doesn't exist in A, but I have mapped as much numbers as possible to those of A.
I know how to get the best matching offset in my case: For every number b in B, calculate the difference between all numbers in A and b. The (positive) difference that occurs most often is the relevant offset. Now, what's a good way to do this in Matlab? Thanks for any hint!