No BSD License  

Highlights from
ObjDiff - Generic object comparator

5.0

5.0 | 1 rating Rate this file 5 Downloads (last 30 days) File Size: 6.27 KB File ID: #14395

ObjDiff - Generic object comparator

by Yair Altman

 

23 Mar 2007 (Updated 27 Jul 2007)

Compares objects of any type inc. Java, Matlab, HG handles, structs, cells & arrays

| Watch this File

File Information
Description

OBJDIFF compares two objects & returns an object of the same type with just the different fields/values. Unlike Matlab's SETDIFF or SETXOR, this OBJDIFF also compares structs, GUI handles, ActiveX, Matlab & Java objects, in addition to arrays & cells. OBJDIFF also allows comparison of numeric cell arrays, unlike SETDIFF/SETXOR. It also accepts anything that SETDIFF/SETXOR accept.
 
Syntax: [objectC,IA,IB] = objdiff (objectA, objectB, options, ...)
 
Inputs:
- objectA - first object to compare
- objectB - second object to compare. Field order in opaque objects does not matter.
    Note: If objectB is not supplied, then objectA(1) is compared to objectA(2)
- options - optional flags as follows:
        'rows' - see documentation for SETXOR
        'dontIgnoreJava' - show different instances of the same java class (default=ignore them)
 
Outputs:
- objectC - object containing only the different (or new) fields, in a {old, new} pattern
- IA,IB - index vector into objectA,objectB such that objectC = [objectA(IA),objectB(IB)] (see SETXOR)
 
Examples:
      >> objectA = struct('a',3, 'b',5, 'd',9);
      >> objectB = struct('a','ert', 'c',struct('t',pi), 'd',9);
      >> objectC = objdiff(objectA, objectB) % a=different, b=new in objectA, c=new in objectB, d=same
      objectC =
          a: {[3] 'ert'}
          b: {[5] {}}
          c: {{} [1x1 struct]}
 
      >> objectC = objdiff(java.awt.Color.red, java.awt.Color.blue)
      objectC =
          Blue: {[0] [255]}
           RGB: {[-65536] [-16776961]}
           Red: {[255] [0]}
 
      >> objectC = objdiff(0,gcf) % 0 is the root handle
      objectC =
            children: {[2x1 struct] []}
              handle: {[0] [1]}
          properties: {[1x1 struct] [1x1 struct]}
                type: {'root' 'figure'}
 
      >> [objectC,IA,IB] = objdiff({2,3,4,7}, {2,4,5})
      objectC =
           3 5 7
      IA =
           2 4
      IB =
           3
 
See also:
      setdiff, setxor, isstruct, isjava, ishghandle, isobject, iscell

MATLAB release MATLAB 7.4 (R2007a)
Other requirements Should work on old Matlab versions but this is untested
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
25 Jul 2007 Darik Gamble

Looks like you forgot to handle the case where objectA and objectB are identical structures.(??? Output argument "objectC" (and maybe others) not assigned)

Other than that, looks good!

28 Jul 2007 Yair Altman

Thanks Darik - I uploaded an update fixing this

Please login to add a comment or rating.
Updates
27 Jul 2007

Fixed handling of identical objects per D. Gamble

Tag Activity for this File
Tag Applied By Date/Time
diff Yair Altman 22 Oct 2008 09:05:31
struct Yair Altman 22 Oct 2008 09:05:31
object Yair Altman 22 Oct 2008 09:05:31
java Yair Altman 22 Oct 2008 09:05:31
activex Yair Altman 22 Oct 2008 09:05:31

Contact us at files@mathworks.com