MATLAB: Find() isn’t finding all the values in the array

findfind when array equals a valuenot finding all valuesvalues in an array

Hi, I have an array (called 'delta') which has been read from excel. This array is of size 33×1. I have a second array (called 'interp_x_array') which I have created using linspace which is of size 1×2601. I want to find the indices of 'interp_x_array' for values in this array equal those in 'delta'.
There are 33 values that are indentical but when I use find(), it only output 30. I have checked these indices and they are correct, however it is missing out 3.
delta values are in a column array of [-22.2000, 14.2000, 16.7000, 19.5000, -22.4000, -15.2000, -1.4000, -6.2000, -1.8000, -73.9000, 29.4000, 3.8000, -6.0000, 22.8000, -20.1000, 32.2000, -1.1000, 1.8000, 15.5000, 51.3000, -119.0000, -71.3000, -82.3000, -21.1000, -11.7000, 16.6000, -5.3000, -37.1000, 37.0000,-2.2000, 10.8000, 3.3000, 1.4000]
if true
% interp_x_array = linspace(-130, 130, 2601);
% delta_mm = xlsread('a.xls', 1, 'F2:F35');
% delta = delta_mm * 1000;
% interp_x_array = round(interp_x_array, 1);
% delta_y_index = find(any(interp_x_array == delta));
end

Best Answer

You are getting the error because of floating point error. To solve this problem use ismembertol() as follow
find(ismembertol(interp_x_array, delta))
it will return 33 elements.