No BSD License  

Highlights from
Compare anything

3.0

3.0 | 3 ratings Rate this file 2 Downloads (last 30 days) File Size: 2.94 KB File ID: #23211

Compare anything

by ygal

 

06 Mar 2009 (Updated 19 Mar 2009)

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

| Watch this File

File Information
Description

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)

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (5)
19 Mar 2009 ygal  
19 Mar 2009 ygal  
19 Mar 2009 Yair Altman

FYI, I published ObjDiff (http://www.mathworks.com/matlabcentral/fileexchange/14395 ) on the File Exchange 2 years ago. ObjDiff is very similar to what you did and also handles HG handles, arrays and COM/Java objects.

26 Mar 2009 ygal

Thanks Yair for your comment.

Indeed, your function ObjDiff return a object similar to the second output of CompareAny.The difference is that CompareAny gives a quantitative difference between two objects, therefore it is more suitable for numeric elements.
This function is very useful for checking results validity and for non-regression testing. It returns also a global maximal difference betwenn the two objects.

Pessah Casher veSameach !

13 May 2009 Gabriel Akira Schreiber

recursive evaluation of nested cell arrays/structs would be desirable.

Please login to add a comment or rating.
Updates
19 Mar 2009

Comment update.

Tag Activity for this File
Tag Applied By Date/Time
compare ygal 06 Mar 2009 10:20:32
structure ygal 06 Mar 2009 10:20:32
cell array ygal 06 Mar 2009 10:20:32
array ygal 06 Mar 2009 10:20:32
cell ygal 06 Mar 2009 10:20:32
string ygal 06 Mar 2009 10:20:32

Contact us at files@mathworks.com