Wednesday, July 10, 2013

Matlab: How to check if structure has any fields

% To check if struct has any fields,
% fieldnames function can use that return cell with
% strings representing fields names if any
%
s = struct();
if numel(fieldnames(s)) == 0
disp('No fields');
end
s = struct([]);
if numel(fieldnames(s)) == 0
disp('No fields');
end
s = struct();
view raw test.m hosted with ❤ by GitHub