Skip to main content

getFieldByNameOrError.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% This function retreived getFieldByName's result, but if the result is
% that the element doesn't exist, it returns an error. This can be used to
% find the field name of required elements and throw a standard error when
% they are not available.
%
% (struct, string) -> (struct)
% Gets field by name or throws error


function output = getFieldByNameOrError(deepStruct, field)
output = getFieldByName(deepStruct, field);
if(~isstruct(output) && ~iscell(output) && ~output)
throw(MException('', strcat(field, " was not found in the struct")))
end
end