File Exchange

image thumbnail

compareStruct

version 1.3 (1.6 KB) by

Compare Structs fields

1 Download

Updated

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.

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)

Jos (10584) (view profile)

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)

Jos (10584) (view profile)

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

1.3

v2 : Changes compare struct like Jos (10584) mention

1.2

Changes suggested by the user Jos (10584) accepted!

MATLAB Release
MATLAB 8.0 (R2012b)

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

» Watch video