Can anyone help resolve this issue?

1 次查看(过去 30 天)
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 个评论
Brian Leon
Brian Leon 2020-4-15
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 2020-4-15
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.

请先登录,再进行评论。

回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by