compStructs - Compare 2 structures and returns diff details

This code compares 2 MATLAB structures (or objects) and returns a cell array with the differences details, one row per difference, if any.

You are now following this Submission

The code receives the 2 structures as inputs (or objects) and will return a cell array with as many rows as differences encountered, if any (an empty cell returned for equal arguments). The 4 columns in the output cell contain details for the differences found:
  • Col 1: field name where difference found
  • Col 2: the reason for the difference
  • Cols 3 and 4: contents for the fields that caused the difference
The code will recurse on nested MATLAB objects to a default maximum of 6 levels, which can be changed with an optional parameter.

Cite As

Jorge Paloschi (2026). compStructs - Compare 2 structures and returns diff details (https://www.mathworks.com/matlabcentral/fileexchange/184712-compstructs-compare-2-structures-and-returns-diff-details), MATLAB Central File Exchange. Retrieved .

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

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

Added a safeguard for cases not implemented
Added support for arrays

1.0.2

Accept objects as well as structures

1.0.1

Added limit on recursion level (defaults to 6)
Added optional parameter for maximum recursion level
Added recursing on objects as well as structures

1.0.0