function Freq = LetterFrequenciesIgnoreSpacesWithPlot(STR) %Freq = LetterFrequenciesIgnoreSpacesWithPlot(STR) %Input: STR = a string of upper case ciphertext w/ (possible) spaces %Output: Freq = a vector of percentages of occurences of each of the %letters A -> Z in Str. A summary table will also be produced in the %command window. This program calls on UCTextWithSpaces2Int %Also, the program creates a barplot Vec = UCTextWithSpaces2Int(STR); SpaceInd = find(Vec == 26); %indices of spaces Vec(SpaceInd) = []; %delete these components before counting frequencies totChars = length(Vec); %total number of characters in STR. fprintf(' Letter Frequency \n') fprintf('===============================\n') for k=0:25 Freq(k+1) = sum(Vec == k)/totChars; fprintf(' %s %f \n', char(65+k), Freq(k+1)); end bar(Freq); barplot = gca; barplot.XTick = 1:26; barplot.XTickLabel = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}