How do I get the least used character in the text file ?
이전 댓글 표시
a= textread('GreatExpectations.txt','%c');
[m]=length(a);
most_used_letter=char(mode(0+a))
댓글 수: 1
Jan
2015년 4월 26일
Is in 'aba' the 'b' or the 'c' the least used character?
채택된 답변
추가 답변 (1개)
per isakson
2015년 4월 26일
편집: per isakson
2015년 4월 26일
Here is a code based on histc
ffs = 'GreatExpectations.txt';
fid = fopen( ffs );
buf = fscanf( fid, '%1c' );
fclose( fid );
letters only
ascii = double( upper( buf ) );
ascii( ascii<double('A') | ascii>double('Z') ) = [];
ascii_ranges = ( double('A') : double('Z') );
[ ascii_counts, ~ ] = histc( ascii, ascii_ranges );
bar( ascii_ranges, ascii_counts, 'histc' )
min_val = min( ascii_counts );
ix_min = find( ascii_counts == min_val );
fprintf( 'The letters, %s, each appears %d time(s)\n' ...
, char('A'+ix_min-1), min_val )
it prints
The letters, JQZ, each appears 1 time(s)
 
카테고리
도움말 센터 및 File Exchange에서 Template Matching에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!