View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Compare Two Structures

Be the first to rate this file! 14 Downloads (last 30 days) File Size: 2.48 KB File ID: #43463 Version: 1.2

Compare Two Structures



11 Sep 2013 (Updated )

Compares two structures for equality

| Watch this File

File Information

    STRUCTCMP(A,B) returns logical 1 (TRUE) if structure A and B are the same
    size, contain the same field names (case sensitive), same field sorting, and same values;
    and logical 0 (FALSE) otherwise.
    If A is defined and you set B = A, STRUCTCMP(A,B) is not necessarily
    true. If A's or B's field contains a NaN (Not a Number) element, STRUCTCMP returns
    false because NaNs are not equal to each other by definition. To considers NaN values to be equal
    use STRUCTCMP(A,B, 'EqualNans', 'on')
    The order in which the fields of each structure were created is important. To ignore the field
    sorting use STRUCTCMP(A,B, 'IgnoreSorting', 'on')

    Field names comparison is case sensitive. To ignore any differences in letter case use
    STRUCTCMP(A,B, 'IgnoreCase', 'on')

    STRUCTCMP(A,B, 'Report', 'on') displays a report on the command window

Required Products MATLAB
MATLAB release MATLAB 7.12 (R2011a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
21 Aug 2015 Stephan Koehler

consider using isequaln, which I think does the job.

Comment only
13 Sep 2013 1.2

- Added error message when any input is not a structure.
- When report is 'on' the checking loop continues until the last field (does not use "break").

Contact us