File Exchange

image thumbnail

numcmp.m

Compares between numerical arrays up to a certain precision.

1 Download

Updated 04 May 2016

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

This program compares numerical arrays up to a certain precision.
Examples:
>> numcmp(x); % compares x==0.1
>> numcmp(x,'<=',y,3); % compares x<=y up to 0.001

See the screenshot for another example.

This is usefull to compare serial dates up to 0.1 seconds by using:
>> numcmp(time1*86400,FUN,time2*86400)
and avoiding floating point problems with the serial dates in days.

Cite As

Carlos Adrian Vargas Aguilera (2019). numcmp.m (https://www.mathworks.com/matlabcentral/fileexchange/21190-numcmp-m), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Thanks, helped me alot!

Jan Orwat

Bug report - precision is not persistent due to the fact that variables are rounded twice (each one once). Moreover, due to code in lines 103:105 overall precision depends on smallest value in arrays.
e.g.:
>> numcmp([0.076; 0],'==',[0.039; 0],1)'

ans =

0 1

>> numcmp([0.076; 1],'==',[0.039; 1],1)'

ans =

1 1

Jan Orwat

Bug report - second output to the function is not returned.
It is specified as variable DT, but later in code another variable BA is used.

Bug report - infinite values are not handled properly.

>> numcmp([1 1],'==',[1 inf],1)

returns error

jiro

Thanks for the entry. I found a small bug. If I put in a row vector, I get an error on line 103:

>> numcmp(round(rand(1,10)),'==',1)

Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in numcmp (line 103)
ABmin = min([A(isfinite(A)); B(isfinite(B))]); % Fixed bug SEP 09, 2008

Updates

1.0.0.0

BSD License

1.0.0.0

Fixed bug with Infs inputs

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: Floating point relational operator.