MATLAB: Serach whether numbers of different arrays are close to each other

similarity

I have 8 arrays of numbers. I want to know whether the numbers of these 8 arrays are close to each other. So for instance
Array1: 1 100 250 400
Array2: 30 89 170 800
Array3: 20 51 870
I want to know whether the numbers meet the condition of being closer than 50 to each other. How do I do this?

Best Answer

  • A = [20 51 870]; % Input vector
    w = 50; % Distances less than this are considered "close"
    dA = abs(diff(A))< w; % Identify which values are "close"
    any(dA) % TRUE if any of the distances are less than 50
    all(dA) % TRUE if all of the distances are less than 50