function removeSourceFiles(h, filenames, groups)
%removeSourceFiles removes specified source files from buildInfo

% Copyright 2019 The MathWorks, Inc.

if nargin < 3
groups = [];
end

if isempty(h.Src.Files)
return;
end

removeIdx = false(size(h.Src.Files));

if ~isempty(filenames)
% If any matching names, mark for removal
idx = ismember({h.Src.Files.FileName}, filenames);
removeIdx(idx) = true;
end

if ~isempty(groups)
% If any matching groups, mark for removal
idx =ismember({h.Src.Files.Group}, groups);
removeIdx(idx) = true;
end

if any(removeIdx)
h.Src.Files(removeIdx) = [];
end