Code covered by the BSD License  

Highlights from
Compare Structures

4.5

4.5 | 10 ratings Rate this file 64 Downloads (last 30 days) File Size: 3.22 KB File ID: #22752

Compare Structures

by michael arant

 

21 Jan 2009

Compares two structured variables recursively and notes where the two structures are different.

| Watch this File

File Information
Description

Structured variables are good for organizing data and manipulating data. However, they can be difficult to check for errors or differences. Function allows each field of a structure to be checked against a corresponding field in a separate structure. Possible outcomes are:
1. Fields agree (both exist and have the same content)
2. Fields do not agree (both exist but contents / values are different)
3. Field exists in only one structure
4. Field type differs (variable class disagreement)

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (11)
11 Mar 2009 Shadi

Works great for me! Thanks

26 Aug 2009 Bass  
16 Sep 2009 Roland Pfister

Yeah - very useful. Thanks a lot!

04 Feb 2010 David Groppe

Thanks! Very helpful.
If would be lovely if you could add an option so that the function only displays mismatches. Displaying all the matches is too much information for the application I'm working on.

05 Feb 2010 michael arant

Thank you David:
I’ll keep that in mind for an upgrade. I intended the pause command to be used to flag mismatched cases. That and the “er” output. When I get the chance, I’ll add an additional input to turn off the echo of all the structure fields.

09 Apr 2010 Christian Komposch  
09 Sep 2010 Florian Dignath

Thank you very much indeed! * * * * *
Sorry for the disturbed rating, my rating always vanishes the moment I click on submit. Both in MS IE and Firefox.

19 Oct 2010 Jaime Undurraga

very nice

03 Dec 2010 Joost den Haan  
05 Feb 2011 Benjamin

This script saved me hours of time... thanks

04 Oct 2011 Keith Beardmore

Thanks - saved me hours.
My fields were in a different order in my two structures so I had to reorder one: comp_struct(s1,orderfields(s1,s2)).

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
equal michael arant 22 Jan 2009 14:43:36
structure michael arant 22 Jan 2009 14:43:36
compare michael arant 22 Jan 2009 14:43:36
compare Peter 20 May 2009 07:58:26
equal Peter 11 Jun 2009 11:17:01
structure Peter 11 Jun 2009 11:17:04
compare RichieRich123 Rich 26 Jun 2009 04:52:21
compare David 29 Mar 2010 17:38:02
compare ninette 14 Apr 2010 10:29:57
compare Thomas Fredholm 01 Aug 2011 07:09:32
equal Thomas Fredholm 01 Aug 2011 07:09:34
structure Thomas Fredholm 01 Aug 2011 07:09:36
compare Giorgio 01 Dec 2011 10:24:43
equal Giorgio 01 Dec 2011 10:24:46
compare Tatjana 11 Dec 2011 12:31:15

Contact us at files@mathworks.com