File Exchange

image thumbnail


version 1.3 (1.6 KB) by

Compare Structs fields

1 Download


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.



v2 : Changes compare struct like Jos (10584) mention


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