isequal Function with Tolerance

Check if two variables of any type are equal. Floating-point numbers are considered equal if the difference is less than a set tolerance.


Updated 18 Feb 2023

View License

Just like the MATLAB function “isequal” checks if two MATLAB variables of any type are equal, but here floating-point numbers are considered equal if the difference is less than a set tolerance. The floating-point numbers can be double or single precision, real or complex, stored in full or sparse numeric arrays. These numeric arrays can be contained in cell and structure arrays, and any combination of these. However, note that the function might be slow for very large structures and cell arrays.
Includes the option to consider NaN-values different and to only check if numeric data is equal.
isequal(1, 1+eps)
isequaltol(1, 1+eps)
A = rand(100, 100);
B = log10(10.^A);
isequal(A, B)
isequaltol(A, B) = {sparse(A(A < 0.5) + 1i*A(A < 0.5))}; = {sparse(B(B < 0.5) + 1i*B(B < 0.5))};
isequal(C, D)
isequaltol(C, D)

Cite As

Patrik Forssén (2023). isequal Function with Tolerance (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2020a
Compatible with R2015a and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Fixed numeric equality test by removing call to ismembertol


Corrected for column and row vectors with same number of elements


Fixed numeric test and added support for tables

Small bug fix for skipping test of non-numeric data...