I have to write a code to find the number of vowels in a word/text file. It has to display the letter, count, and frequency of the vowel. The result I'm getting when I run the code is located at the bottome of the code, so something is either wrong with the while loop for the count, or the fprintf for the count, and the same thing with the frequency.
function [] = vowelfreq(inputfile);inputfile= open('title.txt');countA=0;countE=0;countI=0;countO=0;countU=0;x=0;while x==1:length(inputfile); if inputfile(x)=='a' countA = countA + 1; elseif inputfile(x)=='e' countE=countE + 1; elseif inputfile(x)=='i' countI=countI + 1; elseif inputfile(x)=='o' countO=countO+1; elseif inputfile(x)=='u' countU=countU +1; end end freqA=countA/length(inputfile)*100; freqE=countE/length(inputfile)*100; freqI=countI/length(inputfile)*100; freqO=countO/length(inputfile)*100; freqU=countU/length(inputfile)*100; fprintf('Letter | Count | Frequency\n')fprintf('%c, %d, %.2f\n','a', countA,freqA);fprintf('%c, %d, %.2f\n', 'e', countE, freqE);fprintf('%c, %d, %.2f\n', 'i', countI, freqI);fprintf('%c, %d, %.2f\n', 'o', countO, freqO);fprintf('%c, %d, %.2f\n', 'u', countU, freqU);end
Best Answer