MATLAB: Find matching values plus minus percent

matching value compare

Hi Is there a way to find the matching values with plus minus 5 percent?

Best Answer

Try this:
m = rand(1, 100);
targetValue = 0.5; % Whatever you want
tolerance = 0.05 * targetValue; % 5% tolerance
differences = abs(m-targetValue) % Diff of each element from targetValue. Make sure you use abs()!!!
% Find indexes with tolerance of this
inToleranceIndexes = differences < tolerance
% Report the values that we found to the command window
withinTolerance = m(inToleranceIndexes)