Code covered by the BSD License  

Highlights from
compareStruct

Be the first to rate this file! 11 Downloads (last 30 days) File Size: 1.6 KB File ID: #40124

compareStruct

by

 

01 Feb 2013 (Updated )

Compare Structs fields

| Watch this File

File Information
Description

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.

Required Products MATLAB
MATLAB release MATLAB 8.0 (R2012b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
30 Apr 2013 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!

13 Feb 2013 Jos (10584)

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

07 Feb 2013 Marco Borges

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

04 Feb 2013 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.

Updates
07 Feb 2013

Changes suggested by the user Jos (10584) accepted!

01 May 2013

v2 : Changes compare struct like Jos (10584) mention

Contact us