Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The follwing code must be written in MATLAB: Part A: Create a script called lab4

ID: 3769468 • Letter: T

Question

The follwing code must be written in MATLAB:

Part A:

Create a script called lab4a:

Request a time in HH:MM:SS AM format

Continue to request a time until either a proper time was given or they entered invalid times 5 times in a row. A valid time has an hour between 01 and 12, a minute between 00 and 59, a second between 00 and 59, and the two characters AM or PM

Create a vector ‘time’ in which the first value is the hour on a 24 hour scale (integer), the second value is the minute (integer), the third value is the second (integer).

       For example:   04:34:45 PM   would be stored as time = [16, 34, 45]

Write the time to a string named miltime in the following format:

The time is 16:34:45

Part B:

Create a modular script named lab4b to:

Continue looping accepting patient names and information until a blank input is received.

Module 1: Request a patient’s first and last names

Module 2: Create a user identifier for the person that is the first two letters of their last name capitalized, followed by the first two letters of their first name capitalized, followed by an integer. The integer starts at 1 and increases by one for each new patient.

Explanation / Answer

Answer for part A

time = "11:05:03 PM"
valid = false
while(valid == false)
% read input here
    % fv = input('Please enter a desired future value in dollars', 's');
    tokens = strsplit(time,{':',' '})
  
  
    valid = true;
    hours = str2num(tokens{1,1})
    if( hours < 1 || hours > 12)
        valid = false;
        disp("invalid hours")
    end
  
  
    minutes = str2num(tokens{1,2})

    if(minutes < 0 || minutes > 59)
        valid = false;
        disp("invalid minutes")
    end
  
    seconds = str2num(tokens{1,3})
    if(seconds < 0 || seconds > 59)
        valid = false;
        disp("invalid seconds")
    end
  
    if(strcmpi(tokens{1,4},"AM") == 0 && strcmpi(tokens{1,4},"PM") == 0)
        valid = false;
        disp("invalid meridian")
    end
  
    if(strcmpi(tokens{1,4},"PM") != 0)
        hours = hours+12
    end
end
if(valid == true)
    time = [hours minutes seconds]
  
end

------------------output---------------

Executing the program....
$octave -qf --no-window-system main.m

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote