Can anyone help resolve this issue?

1 view (last 30 days)
Brian Leon
Brian Leon on 15 Apr 2020
Answered: Cris LaPierre on 2 Aug 2020
I currently have a 960x17 char array that consists of cleaned words with no punctuation, special characters, spaces and digits.
I then have a function that is suppose to take in that char array (newWords1) with a cell array (stopWords) to take out the stopWords from my char array.
function stopWord = isStopWord(stopWords, word)
%determines if a word is a stopword
%Input: stopWords: is a Cell Array that contains all the words from
% the file stopWords.txt
% word: is a Character Array
%Return:
% stopWord: is logical(1)/TRUE if word IS a stopword otherwise it is
% logical(0)/FALSE if it is NOT a stopword
hasWord = ismember(stopWords,word);
stopWord = any(hasWord);
end
This is the code i am running to use this function
%removing the stopwords from the story files (isStopWord)
fid = fopen('stopWords.txt');
stopWords = textscan(fid,'%s');
stopWords = stopWords{1};
stopWord = isStopWord(stopWords,newWords1);
end
The problem is that when I run this, instead of recieivng a structure array with the stopWords removed from my char array, I just recieve a variable stopWord with a logical 1 statement. Any tips on how to resolve this?
  3 Comments
Brian Leon
Brian Leon on 15 Apr 2020
Oh i see now. Is there any way I can make my char array stopWords1 plug each word into my fucntion to remove the stopwords? My goal is to remove stopwords from my stopWords1 variable from my list of stopWords.
Geoff Hayes
Geoff Hayes on 15 Apr 2020
Are you replacing the stopWords from your newWords1 with something else (blank spaces) or just removing altogether? A problem with just removing them is that now you are reducing the number of characters in one or more rows so newWords1 will no longer be 960x17. If each line corresponds to a line of text, then it might be better to convert this character array to a 960 element cell array where each cell corresponds to one of these lines of text, and the length of each line does not have to be identical.

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 2 Aug 2020
Do you have access to the Text Analytics Toolbox? If so, consider using the removeWords function.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!