I have a text file that I would like to split into an array. Each array cell should be a word, not a sentence or line in the file.
Ältere Kommentare anzeigen
This is what I got so far. But it does not actually solve my problem.
file= fopen('marktwain.txt','r');
string= fread(file, [1, inf], 'char');
fclose(file);
CStr = dataread('file', 'marktwain.txt', '%s', 'delimiter', '\n');
I have little clue where to go from here.
Akzeptierte Antwort
Weitere Antworten (2)
Walter Roberson
am 17 Mär. 2013
file = fopen('marktwain.txt', 'rt');
CStr = textscan(file, '%s');
fclose(file);
Only problem: you have not defined exactly what a "word" is for your purposes, so the above is going to break things up at whitespace.
1 Kommentar
Marco
am 17 Mär. 2013
Image Analyst
am 17 Mär. 2013
Bearbeitet: Image Analyst
am 17 Mär. 2013
For example:
>> allwords('This is what I got so far. But it does not actually solve my problem.')
ans =
'This' 'is' 'what' 'I' 'got' 'so' 'far' 'But' 'it' 'does' 'not' 'actually' 'solve' 'my' 'problem'
2 Kommentare
Marco
am 17 Mär. 2013
Walter Roberson
am 17 Mär. 2013
Yes you would have to download it from the link that was given.
Kategorien
Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!