建于
this solution:
a = [10+8i, 20];
b = [10+9i, 30, 40+3i, 55];
c = [10, 60, 41+3i];
M1 = compare_vectors(a , b);
M2 = compare_vectors(a , c);
M3 = compare_vectors(b , c);
finalVec = [M1, M2 , M3]
function M = compare_vectors(a , b)
% All combinations of vectors elements
[A,B] = meshgrid(a,b);
C = cat(2,A',B');
D = reshape(C,[],2);
% Find differences lower than tolerance
tolerance = 1.5
below_tolerance = abs(D(:,1) - D(:,2)) < tolerance ;
% If none, return empty
if all(below_tolerance== 0)
M = [];
return
end
% Calculate average of returned values
M = mean(D(below_tolerance,:));
end