isequal Function with Tolerance
Version 1.2 (3,16 ko) par
Patrik Forssén
Check if two variables of any type are equal. Floating-point numbers are considered equal if the difference is less than a set tolerance.
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.
Examples:
clear
isequal(1, 1+eps)
isequaltol(1, 1+eps)
A = rand(100, 100);
B = log10(10.^A);
isequal(A, B)
isequaltol(A, B)
C.data = {sparse(A(A < 0.5) + 1i*A(A < 0.5))};
D.data = {sparse(B(B < 0.5) + 1i*B(B < 0.5))};
isequal(C, D)
isequaltol(C, D)
Citation pour cette source
Patrik Forssén (2024). isequal Function with Tolerance (https://www.mathworks.com/matlabcentral/fileexchange/113375-isequal-function-with-tolerance), MATLAB Central File Exchange. Récupéré le .
Compatibilité avec les versions de MATLAB
Créé avec
R2020a
Compatible avec les versions R2015a et ultérieures
Plateformes compatibles
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Découvrir Live Editor
Créez des scripts avec du code, des résultats et du texte formaté dans un même document exécutable.
Version | Publié le | Notes de version | |
---|---|---|---|
1.2 | Fixed numeric equality test by removing call to ismembertol |
||
1.1.1 | Corrected for column and row vectors with same number of elements |
||
1.1 | Fixed numeric test and added support for tables |
||
1.0.1.0 | Small bug fix for skipping test of non-numeric data... |
||
1.0.0 |