ways to check if a strucutre is empty in matlab

One way to check if a structure is empty in Matlab is to use the isempty function.

main.m
if isempty(myStruct)
    disp('myStruct is empty')
else
    disp('myStruct is not empty')
end
94 chars
6 lines

Another way to check if a structure is empty is to use the fieldnames function and check if there are any fields in the structure.

main.m
if isempty(fieldnames(myStruct))
    disp('myStruct is empty')
else
    disp('myStruct is not empty')
end
106 chars
6 lines

related categories

gistlibby LogSnag