I have three vectors in Matlab that are possibly of different sizes. I want to compare the values in each vector against all the other values in the other vectors and only keep values that are 'close' in 2 out of 3 of the vectors. And by 'keep', I mean take the average of the close values.
For example:
a = [10+8i, 20];
b = [10+9i, 30, 40+3i, 55];
c = [10, 60, 41+3i];
If I set a closeness tolerance such that only values that are within, say, a magnitude of 1.5 of each other are kept, then the following values should be marked as close:
- 10 + 8i and 10 + 9i
- 40 + 3i and 41 + 3i
Then the routine should return a vector of length that contains the average of each of these sets of numbers:
finalVec = [10+8.5i,40.5+3i];
What is the most efficient way to do this in Matlab? Is there a better way than just straightforward looping over all elements?