Skip to main content

getFieldByNameOrAlternate.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% This function returns the first instance of a field matching the given
% name and can be used to find a field in a struct that has been parsed
% from and XML (xml2struct), or returns an alternative value if the field
% is not found
%
% (struct, field, Any) => (Any)
% Find first instance of field in nested struct or a given alternative


function output = getFieldByNameOrAlternate(struct, field, alternative)
output = getFieldByName(struct, field);
if ~isnumeric(output) && ~isstruct(output)
try
if output == 0
output = alternative;
end
catch
return
end
end
end