Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
My issue with textscan, can anyone help?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a textfile that consists of 174 stopWords and it is structured as shown ,
a
about
above
after
against
all
am.... and so on
fid = fopen('stopwords.txt');
stopWords = textscan(fid,'%s');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/283522/image.png)
This is the code I wrote to make the textfile into a cell array but it is making the variable stopWords a 1x1 cell that contains the 174x1 cell of stopwords inside it. How would I edit my code to make my variable stopWords just be a 174x1 cell array?
0 Kommentare
Antworten (1)
Walter Roberson
am 10 Apr. 2020
Bearbeitet: Walter Roberson
am 10 Apr. 2020
stopWords = stopWords{1};
Or you could use a different approach:
stopWords = regexp(fileread('stopwords.txt', '\s+', 'split'));
if isempty(stopWords{end}); stopWords(end) = []; end
The isempty() test has to do with the fact that after the last word in the file there might be whitespace or newline.
0 Kommentare
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!