Code covered by the BSD License  

Highlights from
findTol

4.0

4.0 | 1 rating Rate this file 10 Downloads (last 30 days) File Size: 2.08 KB File ID: #27298

findTol

by

 

19 Apr 2010 (Updated )

Finds elements in an array that approximate a given value, to within a specified error tolerance.

| Watch this File

File Information
Description

Finding elements in an array that approximate a given value, to within a specified error tolerance, is a common task. This very simple script automates this task and furthermore outputs the relevant elemental indices in order of smallest to largest error, making it easy to select only the n closest matches.
Either a relative, percent or absolute error tolerance may be specified. Numeric arrays of all dimensions are supported.

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
09 Jul 2010 Vinesh Rajpaul

Thanks - will implement your suggested improvements.

23 Jun 2010 Jan Simon

This is a strange method to sort the replied indices:
I = sortrows([I, epsilon(I)], 2) * [1; 0]
This would be more efficient:
[dummy, Index] = sort(epsilon(I));
I = I(Index);
Applying relative tolerances to small values is a general problem. Perhaps it would be nicer to catch Value==0 for "relative" error directly, but at least a div-by-zero warning appears automatically.
I'd expect that Tol=0 performs an exact comparison, although this is nonsense for floating point calculations.
Descriptive help section, no standard H1-line, "See also", author and version, example, number of inputs checked (the MsgID starting with "MATLAB" looks like findTol belongs to a Matlab toolbox). Summary: Useful and usable, small improvements possible.
See also Bruno's ISMEMBERF: http://www.mathworks.com/matlabcentral/fileexchange/23294

Updates
21 Jun 2010

Fixed a problem with sorting row vectors that caused the script to crash

22 Jul 2010

Implemented some of Jan Simon's suggested improvements

Contact us