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.
07 Feb 2013
Changes suggested by the user Jos (10584) accepted!
01 May 2013
v2 : Changes compare struct like Jos (10584) mention