Using a forloop write the MATLAB code that will read in 1 se
Using a for-loop. write the MATLAB code that will read in 1 sentence and count the number of uppercase letters. Recall that the ASCII uppercase letters are 65 to 90 (i.e., A to Z). For example, if I enter the following sentence, I should identify 10 uppercase letters: The Quick Brown Fox Jumps Over The Lazy Brown Dog!
Solution
% program to count the number of upper case letters in a given string
count=0;
my_string = \'The Quick Brown Fox Jumps Over The Lazy Brown Dog\';
str_ascii = uint8(my_string) % 8-bit ascii values
str_back_to_char= char(str_ascii)
str_16bit = uint16(my_string) % 16-bit ascii values
for i=uint16(my_string)
if((i>=65)&&(i<=90))
count=count+1;
end
end
fprintf(\'count of uppercase letters: %d\ \', count);
