% your data
a = [10+8i, 20];
b = [10+9i, 30, 40+3i, 55];
c = [10, 60, 41+3i];
tol = 1.5;
% call the function with each combination of vectors and concatenate the results
finalVec = cell2mat(cellfun(@closepoints, {a, a, b}, {b, c, c}, {tol, tol, tol}, 'Uni', 0))
function p = closepoints(a, b, tol)
% find the pairs of indexes of close points
% the bsxfun() part calculates the distance between all combinations of elements of the two vectors
[ii,jj] = find(abs(bsxfun(@minus, a, b.')) < tol);
% calculate the mean
p = (a(jj) + b(ii))/2;
end
, cellfun() , for. , , , .