. X, , , , , real_tol imag_tol. , .
function X_unique = unique_complex_with_tolerance(X,real_tol,imag_tol)
X_sorted = sort(X); %Sorts by magnitude first, then imaginary part.
dX_sorted = diff(X_sorted);
dX_sorted_real = real(dX_sorted);
dX_sorted_imag = imag(dX_sorted);
remove_idx = (abs(dX_sorted_real)<real_tol) & (abs(dX_sorted_imag)<imag_tol);
X_unique = X_sorted;
X_unique(remove_idx) = [];
return
Please note that this code will remove all elements that satisfy this difference tolerance. For example, if X = [1 + i, 2 + 2i, 3 + 3i, 4 + 4i], real_tol = 1.1, imag_tol = 1.1, then this function will return only one element, X_unique = [4 + 4i], even though you you can consider, for example, X_unique = [1 + i, 4 + 4i] as a valid answer.
source
share