How do I get the least used character in the text file ?
Mostra commenti meno recenti
a= textread('GreatExpectations.txt','%c');
[m]=length(a);
most_used_letter=char(mode(0+a))
1 Commento
Jan
il 26 Apr 2015
Is in 'aba' the 'b' or the 'c' the least used character?
Risposta accettata
Più risposte (1)
per isakson
il 26 Apr 2015
Modificato: per isakson
il 26 Apr 2015
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)
 
Categorie
Scopri di più su Template Matching in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!