File Exchange

image thumbnail


version (1.6 KB) by Marco Borges
Compare Structs fields

1 Download

Updated 01 May 2013

View Version History

View License

compareStruct compares Structs fields and returns logical 1 (true) if the input structs have the same fields, and logical 0 (false) otherwise, no matter their content.

Cite As

Marco Borges (2021). compareStruct (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Marco Borges

Hey Jos(10584), sorry for the delay in notice that the code had not been updated!
Just send version 2 reviewed in February!

Jos (10584)

Something seems amiss. I do not see any code changes, Marco.

Marco Borges

Thanks for the suggestions. Were accepted and the code remade.

Jos (10584)

The code can be replaced by a one-liner:
B = isequal(sort(fieldnames(a)), sort(fieldnames(b)))

I do like the fact that you have written a clear help section, including a H1 line. As for your code, as soon as B becomes false in the for-loop you can issue a return command (no need to check the remaining field names).
You also might want to check if the input are indeed structures.

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!