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!
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...
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.
write a Matlab function file to solve system Ax=b by using the output of the function...
write a Matlab function file to solve system Ax=b by using the output of the function lufac2a your function should have inputs f=matrix return from lufac2a, piv=array return by lufac2a and b=right hand side of your system.the only output for your system should be x guideline 1.use the column access for the matrix entries 2. do not create any other matrix in your function-get your data directly from the matrix passed into your function 3.do not use Matlab command designed...
When using the import wizard in MATLAB to import data fro, a .csv file the data...
When using the import wizard in MATLAB to import data fro, a .csv file the data appears in MATLAB in the following format "35:53.2" how do I convert this into more usable matlab values? I think that the duration function was used to generate the time format. The code will need to be written in MATLAB software I will leave feedback if you are able to provide a correct response. Thank you
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT