function n = id2ndx(annotation, id)
% n = findLMobjectID(annotation, id)
%
% pass an 'id' and it returns the object index in the annotation struct
% n = 0 if the id is not found.

if isfield(annotation, 'object')
    annotation_id = [annotation.object.id];
    
    n = [];
    for i = 1:length(id)
        tmp = find(annotation_id==id(i));
        
        if isempty(tmp)
            warning(sprintf('Object id (%d) not found.', id(i)))
        else
            n(i) = tmp;
        end
    end
else
    warning('Empty annotation. Object id not found.')
end

