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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284713/image.png)
3 件のコメント
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 件)
参考
カテゴリ
Help Center および File Exchange で Text Data Preparation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!