%% Remove Words from Bag-of-Words Model by Index
% Remove words from a bag-of-words model by inputting a vector of numeric indices to removeWords.
% Create an array of tokenized documents.

documents = tokenizedDocument([
    "I love MATLAB"
    "I love MathWorks"]);
bag = bagOfWords(documents)

% View the vocabulary of bag.

bag.Vocabulary

% Remove the first and third words of the vocabulary from the bag-of-words model by specifying the numeric indices [1 3].

idx = [1 3];
newBag = removeWords(bag,idx)

% Alternatively, you can specify logical indices.

idx = logical([1 0 1 0]);
newBag = removeWords(bag,idx)

% Copyright 2012 The MathWorks, Inc.