Compare anything

Compares quantatively structs, cell, array, element by element.

You are now following this Submission

The 'compareAny' function is useful if you have two objects of the same type and same size, in case of structs, also the fields must be the same.
It determines the relative difference if element is number (0 if numbers are equals) ; if it is a character, it gives 0 if they are same, and 1 otherwise.
It outputs the maximal relative difference and an object holding the detailled differences.

It calls the subfunction anytrue, which extends the any function for all classes.

% COMPAREANY - calcul relative difference between two objects, element by element
%
% Syntax :
% [ecartMax, C] = compareAny(A,B)
%
% Inputs :
% A - structure, cell array, number, logical or string
% B - structure, cell array, number, logical or string, same class as A
%
% Outputs :
% ECARTMAX - the maximal relative difference between A and B
% C - same class as A and B, holding 0 if element of A and element of B are equals ;
% otherwise, relative difference (for different character, it is always 1)
%
% Examples:
% >> a = {'bla',1,[1,31]};
% >> b = {'blo',1,[1,25]};
% >> [ecartMax, C] = compareAny(a,b)
% ecartMax =
% 0.1935
% C =
% [1] [0] [1x2 double]
%
% >> C{1,3}
% ans =
% 0 0.1935
%
% Other m-files required: none
% Subfunctions: ANYTRUE
% MAT-files required: none
%
% See also: COMPARE, by Dario (Matlab Central)
%
% Author: Nahouto
% Last revision: 02/19/09
% Created with Matlab version: 7.6.0.324 (R2008a)

Cite As

ygal (2026). Compare anything (https://www.mathworks.com/matlabcentral/fileexchange/23211-compare-anything), MATLAB Central File Exchange. Retrieved .

Categories

Find more on Operators and Elementary Operations in Help Center and MATLAB Answers

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.1.0.0

Comment update.

1.0.0.0