% This function reads out a field from a struct and sets it to a default
% value if not there

% Usage:  field = read_opt(struct,fieldname,defaultvalue)

function x = read_opt(opt,name,default)

if isfield(opt,name) ~= 1
    x = default;
else
    x = opt.(name);
end

end