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.
이전 댓글 표시
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.
채택된 답변
추가 답변 (2개)
Walter Roberson
2013년 3월 17일
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.
Image Analyst
2013년 3월 17일
편집: Image Analyst
2013년 3월 17일
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
Marco
2013년 3월 17일
Walter Roberson
2013년 3월 17일
Yes you would have to download it from the link that was given.
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!