How do I get the least used character in the text file ?
Mostrar comentarios más antiguos
a= textread('GreatExpectations.txt','%c');
[m]=length(a);
most_used_letter=char(mode(0+a))
1 comentario
Jan
el 26 de Abr. de 2015
Is in 'aba' the 'b' or the 'c' the least used character?
Respuesta aceptada
Más respuestas (1)
per isakson
el 26 de Abr. de 2015
Editada: per isakson
el 26 de Abr. de 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)
 
Categorías
Más información sobre Template Matching en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!