Can anyone help resolve this issue?

1 visualización (últimos 30 días)
Brian Leon
Brian Leon el 15 de Abr. de 2020
Respondida: Cris LaPierre el 2 de Ag. de 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 comentarios
Brian Leon
Brian Leon el 15 de Abr. de 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 el 15 de Abr. de 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.

Iniciar sesión para comentar.

Respuestas (1)

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

Categorías

Más información sobre Text Data Preparation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by