Questions Regarding Matlab & Txt Files

1. how would I create a variable in Mlab to hold the text file
2. what about seeing how many certain letters are present in the variable (ie: how many "b's" are in txt file 'tfile'
3. which word is most frequent

回答 (1 件)

Matt Kindig
Matt Kindig 2012 年 11 月 26 日

0 投票

To read the text file into a variable:
txt = fileread('/path/to/text/file.txt')
To get the number of 'b''s in a file.
numB = sum( ismember(txt, 'b'));
Most frequent word is a bit tricky. Your best bet might be to use one of the solutions already posted on the File Exchange, such as this one http://www.mathworks.com/matlabcentral/fileexchange/19505-wordcount

1 件のコメント

Walter Roberson
Walter Roberson 2012 年 11 月 26 日
sum(txt == 'b')

この質問は閉じられています。

質問済み:

2012 年 11 月 26 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by