Lab 3
Creating MATLAB Programs
CS211 Lab Policy:
- This lab exercise will not be graded.
- Submit as much as you have completed before the end of the lab period in
which it is assigned.
- If you do not finish this lab work, it is to your advantage to finish it
outside of class. Please re-submit your finished work to the course web
site.
- You may receive help from anyone in completing this lab.
- You may not submit another student's code as part of your
lab.
Instructions:
- Create a MATLAB program named lab3a
that displays your rank and full name on one line and your major on the
immediately following line. For example, your program output should
look something like the following:
C2C Phillip K. Templeton
Operations Research
Ensure your program is an appropriately named and commented
function. Save and run your program. Correct any errors you
find.
- The equation for converting
from degrees Fahrenheit to degrees Celsius is
Degrees_Celcius = (Degrees_Fahrenheit -
32)*5/9
Create a MATLAB program named
lab3b that inputs a temperature in degrees Fahrenheit and
outputs the equivalent temperature in degrees Celsius. Use the
input function
to prompt for and get a temperature value from the user. Your output
temperature must be displayed with a single digit after the decimal point and should match
the format shown below. Ensure your program is appropriately commented
and that you use descriptive variable names. Run your program and
correct any errors. An example of how your program should look if the
user enters 70 degrees follows.
Enter temperature in degrees Fahrenheit:
70
That is 21.1 degrees Celsius.
- Using MATLAB help, find out what the
date() and
clock()
functions do. Create a MATLAB program named
lab3c
that displays
the current date one line and the current time, in military format, on the
second line. You program must match the exact format of the
example shown below. If you run your program at 9:05PM on 11 March
2006, your program must display the following.
The current date is 11-Mar-2006.
The current time is 09:05.
Make sure the subsequent command prompt (>>)
is on the line following your second line (not at the end of the second
line). Hint: Use fprintf()
and the leading zero modifier flag to force a zero when the hours or minutes are only
a single digit. Ensure your program is an appropriately named and commented function.
Save and run your program. Correct any errors you find.
Turn-in:
Submit your
lab3a.m, lab3b.m, and lab3c.m
files to the course web site.