Question

In: Computer Science

MATLAB; How to find LowerCaseCount, UpperCaseCount, NumericCount, OtherCount. Using the input file of characters, determine %...

MATLAB; How to find LowerCaseCount, UpperCaseCount, NumericCount, OtherCount.

Using the input file of characters, determine

% the number of characters that meet the following criterion. Each output

% variable will be a 1 x 1 scalar (i.e. how many of each there are).

% Input: 'Matlab_Wikipedia.mat' (variable name is Contents)

% Output: LowerCaseCount, UpperCaseCount, NumericCount, OtherCount

Solutions

Expert Solution

MATLAB Code:

function [LowerCaseCount, UpperCaseCount, NumericCount, OtherCount] = characterCriteria (contents)
    % Function that counts the number of characters that matches each criteria
  
    % Initializing output variables to 0
    LowerCaseCount = 0;
    UpperCaseCount = 0;
    NumericCount = 0;
    OtherCount = 0;
  
    % Opening file in read mode
    fp = fopen(contents, "r");
  
    % Reading data from file
    data = fscanf(fp, "%s");
  
    % Iterating over char by char
    for i = 1:length(data)
      
        % Checking for numbers
        if isdigit(data(i))

            % Updating numbers count
            NumericCount += 1;
          
        % Checking for lower case letters
        elseif islower(data(i))
      
            % Updating lower case count
            LowerCaseCount += 1;
          
        % Checking for upper case letters  
        elseif isupper(data(i))
      
            % Updating upper case count
            UpperCaseCount += 1;
          
        % Other characters  
        else
          
            % Updating other count
            OtherCount += 1;
          
        endif
  
    endfor
  
    % Closing file  
    fclose(fp);

endfunction

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sample Output:


Related Solutions

In this exercise, you will be given a system with their input/output relationships. Using MATLAB, determine...
In this exercise, you will be given a system with their input/output relationships. Using MATLAB, determine whether the system below are a) linear/non-linear b) time-invariant/timevariant, c) causal/noncausal, d) has memory/memoryless: y[n] = x2[n] Provide MATLAB code and graphs to show your work for the linearity and time-invariance testing
Create a MATLAB script file to determine the given function is continuous or discontinuous at given...
Create a MATLAB script file to determine the given function is continuous or discontinuous at given interval (points).
To find a positive root for , write a MATLAB script file that uses Bisection method....
To find a positive root for , write a MATLAB script file that uses Bisection method. Choose any initial value that is needed. Use absolute relative approximate error to be less than 0.01. Your code should report the number of iteration and the value of x.
Using Matlab's FUNCTION FILE Solve this system of equations using Gauss Elimination in MATLAB by writing...
Using Matlab's FUNCTION FILE Solve this system of equations using Gauss Elimination in MATLAB by writing a Function file. 10y + z = 2 x + 3y – z = 6 2x + 4y + z = 5 Could you also provide me with a copiable function file of Matlab and the associated screenshot. Thank you!
MATLAB question: how do you write a video file using videowriter without displaying the current figure...
MATLAB question: how do you write a video file using videowriter without displaying the current figure when doing getframe? I want to go through the data packet Xpixels x Ypixels x Zframes for each frame and write it to a video without showing the display until it's finally done. also I noticed if I turn the figure off the code runs much much slower using fig = figure(visible off). is there anyway to avoid this sluggishness? and speed it up...
For this assignment, using MATLAB you are to read from an Excel file “theInputFile.xlsx” an undetermined...
For this assignment, using MATLAB you are to read from an Excel file “theInputFile.xlsx” an undetermined number of rows and columns. The first task of your program is to find out if the data in the file is in a square matrix. If it is not square the program will give us a statement telling us the data is not complete. If it is square then the program proceeds and will find the average of the rows one row at...
The input file Each line of the input file will contain a sentence with words separated...
The input file Each line of the input file will contain a sentence with words separated by one space. Read a line from the listed below  and use a StringTokenizer to extract the words from the line. The input file . Mary had a little lamb whose fl33ce was white as sn0w And everywhere that @Mary went the 1amb was sure to go. Read the above that contains a paragraph of words. Put all the words in an array, put the...
Write a C program to find out the number of words in an input text file...
Write a C program to find out the number of words in an input text file (in.txt). Also, make a copy of the input file. Solve in C programming.
Using Matlab, write a function that takes numeric data as its input argument and prints a...
Using Matlab, write a function that takes numeric data as its input argument and prints a message to the Command Window stating if the number is positive, or negative, or 0. This function should transfer an output value to the Workspace ONLY when the input value is negative. Please include a copiable code and the associated screenshots.
write a matlab function for frequency analysis using DFT. the function should take as input a...
write a matlab function for frequency analysis using DFT. the function should take as input a signal, and as output the number of sinusoids and their frequencies.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT