필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
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 CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by