Practice Test
Click here for data and code files necessary to complete the practice problems.

The provided text file (
readings.txt
) contains a timestamp broken up into year, month, day, hour, minute, second, and timezone components, as well as a reading from a sensor. Write a script that reads the data from the file using thetextscan
function.The script must:
 Convert the timestamps into single numeric serial date numbers stored in a variable named
dates
 Ignore the timezone component of the timestamp by not reading it into the workspace
 Place numeric values for the readings in a single array of type
double
with a variable name ofreadings
 Convert the timestamps into single numeric serial date numbers stored in a variable named

The provided data file (
viewdata.mat
) contains a 19by3 matrixviewdata
with the following columns: Video Length  Length in minutes for the video
 Views  Number of times the video has been viewed
 Minutes Watched  Total amount of time viewers spent watching the video
Write a MATLAB script to analyze the data to determine the effect of video length on viewer retention with the following steps:
 Load the saved viewership data into the MATLAB workspace.
 Create the column vector
viewPct
containing the percentage viewed for each variable according to the formula: Percentage viewed = (Minutes watched / Views) / (Video length).  Create vectors containing the percentage viewed for short (Video length < 1.5), medium (1.5 <= Video length <= 2.25), and long (Video length > 2.25) videos).
 Calculate the average of the values contained in the vectors from the previous step, and store the results in the variables
shortPct
,medPct
, andlongPct
respectively.

The provided data file (
TData.mat
) contains temperature data reported by weather stations instance in time. The contents of the data file are: The xcoordinates of the weather station locations (in km) stored in the column vector
x
 The ycoordinates of the weather station locations (in km) stored in the column vector
y
 The temperature data corresponding to the station locations (in degrees C) stored in the column vector
T
Write a MATLAB script to load the data from the file and produce a contour plot similar to the one below with the temperature stations. Use the
griddata
function with'v4'
as the interpolation method to estimate the temperatures for the xy spatial grid points.The plot must contain:
 contours spanning 5 degrees C to 5 degrees C in 1 degree increments
 a spatial extent of the contour plot corresponding to 0 < x < 675, 0 < y < 350; with a grid resolution (grid square size) of 1kmby1km.
 labels for the contours with the
clabel function
 markers for the weather station locations
 The xcoordinates of the weather station locations (in km) stored in the column vector

Create an anonymous function
f
which accepts a (possibly vector valued) numeric input and returns a (possibly vector valued) numeric output according to the mathematical formula f(x) = x^2  sin(x). Use this function along with thefminsearch
function to find the local minimum value near the initial value nearx0 = 0.5.
Store the local minimizing value and the corresponding function value in the variablesxmin
andymin
respectively. 
A function called
viewImage
accepts an image and a variable number of parameter name/value pairs as shown in the function heading:function viewImage (I, varargin)
Write the validation code in the body of the function to produce an error message explaining the violation if any of the following conditions on the input arguments are not met:
 If variable input options exist, they must exist in pairs
 The names portion of the variable input must occur before the corresponding value. Names must be strings of the value
'zoom'
,'rotate'
, or'tilt'
 The value portion for a variable input must be numeric
Do not write any implementation beyond the code required to perform the validation.

The provided script
(diceSimulation.m)
runs a simulation of rolling six, 6sided dice and calculating the sum. The simulation is repeated 1,000,000 times to create a histogram of the probability distribution as shown below.The code produces the correct result, but can be improved to run faster. Rewrite the script such that the simulation produces the same results with 1,000,000 trials, a histogram of the results is created, and a faster execution time.
The figure illustrates on result from running the script. Solutions should have a similar distribution.

The provided script
(LoadData.m)
loads data from an impact simulation, and uses theplotyy
function to plot position on the left yaxis and velocity on the right yaxis. Using the outputs from theplotyy
function, modify the figure to make it look as shown in the figure below.The figure must contain:
 an xaxis with a minimum value of 0 and a maximum value of 4
 a plot of the position vector as a solid blue line
 a left yaxis colored in blue with a minimum value of 5 and a maximum value of 5
 a plot of the velocity vector as a dashed black line
 a right yaxis colored in black with a minimum value of 0.5 and a maximum value of +0.5
 a right yaxis colored in black with a minimum value of 0.5 and a maximum value of +0.5
 a title reading "Impact Data" as shown in the figure
 a legend in the top center of the axes with the correct label for each plot

The provided graphical application (see screenshot below) plots a sine wave based on the provided amplitude and frequency using the equation
y = amplitude*sin(2*pi*frequency*x)
on the interval defined by[0 2*pi].
Write the callback functions for the slider controls to update the plot. The callbacks must:
 Update the plot with the new amplitude or frequency
 Update the display of the amplitude and frequency values (tag names
edtAmplitude
andedtFrequency
respectively.
Additionally, display a plot with the default values for amplitude and frequency upon starting the application.