I have 400 files, each one contains about 500000 character, and those 500000 characters consists only from about 20 letters. I want to make a histogram indicating the most 10 le
Since you have an array of uchar, you know that your elements will always be in the range 0:255. After seeing Tamás Szabó's answer here I realized that the null character is exceedingly unlikely in a text file, so I will just ignore it and use the range 1:255. If you expect to have null characters, you'll have to adjust the range.
In order to find the 10 most frequently-used letters, we'll first calculate the histogram counts, then sort them in descending order and take the first 10:
counts = histc(uint8(part), [1:255]);
[topCounts, topIndices] = sort(counts, 'descend');
Now we need to rearrange the counts and indices to put the letters back in alphabetical order:
[sortedChars, shortIndices] = sort(topIndices(1:10));
sortedCounts = topCounts(shortIndices);
Now we can plot the histogram using bar:
bar(sortedCounts);
(You can add the 'hist' option if you want the bars in the graph touching like they do in the normal hist plot.)
To change the horizontal legend from numeric values to characters, use sortedChars as the 'XtickLabel':
labelChars = cellstr(sortedChars.').';
set(gca, 'XtickLabel', labelChars);