フィルターのクリア

how to find the total no of letters in a text file in matlab

3 ビュー (過去 30 日間)
Muhammad Usman Saleem
Muhammad Usman Saleem 2015 年 6 月 8 日
コメント済み: Walter Roberson 2016 年 9 月 23 日
Hi ;
I am going to make a function called letter_counter that takes the name of a text file as input and returns the number of letters (i.e., any of the characters, a-to-z and A-to-Z) that the file contains. i have given that hint: You can use the built-in function isletter. If there is a problem opening the file, the function returns -1.
I am going that code but do not know what i am doing
function m=letter_counter(file)
fid=fopen(file,'rt')
m = char(fread(fid,inf));
fclose
if fid~=fopen(file,'rt')
m=-1;
end
end
I am getting that error
Feedback: Your program made an error for argument(s) 'letter_counter.m'
Your solution is _not_ correct.
I do not know what i have made. Please assist about the correct one. Thanks in advance for assistance...
  6 件のコメント
Kapil Dhanwani
Kapil Dhanwani 2016 年 9 月 23 日
what to do if i want to count number of digits(0-9) not letter?
Walter Roberson
Walter Roberson 2016 年 9 月 23 日
You would read the help documentation for isletter() and check out the various routines mentioned in 'See Also'

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2015 年 6 月 8 日
Your m is just all the bytes read. It's not taking into account that there are other characters like punctuation marks that they do not want counted. I don't see where you're checking if the character is in the range a-z or A-Z. Where are you doing anything like
letters = (m >= 'a' & m <= 'z') | (m >= 'A' & m <= 'Z');
That's why it's not giving the correct answer. Now do you know what letters above is? Do you know what you would do with that to count the valid letters?
  6 件のコメント
Muhammad Usman Saleem
Muhammad Usman Saleem 2015 年 6 月 11 日
@image i do not gets your view... where i required a line for the collection of strings? how can i store these strings????
Image Analyst
Image Analyst 2015 年 6 月 13 日
There is no line like this:
m = char(fread(fid,inf));
like you had before. Why did you remove that line?

サインインしてコメントする。

その他の回答 (1 件)

charu sharma
charu sharma 2015 年 8 月 27 日

カテゴリ

Help Center および File ExchangeText Data Preparation についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by