CS211 Lab Policy:
Instructions:
For this lab you will create the function lab20() saved in file lab20.m along with one user-defined sub-function also saved in lab20.m. Add code to your function that performs the following:
Define a sub-function named
box() that has 3 input arguments and one
output argument. The input arguments represent the number of rows, columns,
and layers of the 3-D matrix created by box
and returned as the output argument. All internal elements of the
3-D matrix returned by box must be
zeros and all external elements (those in the first or last row,
first or last column, or first or last layer), must be 1. For example, the
function call:
box(3, 4, 3)
should return the matrix:
(:,:,1) =
1 1 1 1
1 1 1 1
1 1 1 1
(:,:,2) =
1 1 1 1
1 0 0 1
1 1 1 1
(:,:,3) =
1 1 1 1
1 1 1 1
1 1 1 1
Add the box
function definition as a sub-function at the end of
lab20.m. Add to your
lab20() function (the main program) code
that does the following.
get from the user a number of rows
get from the user a number of columns
get from the user a number of layers
call box with the user inputs as its 3 input arguments
display the 3-D matrix returned by
box (using
disp)
Create a multidimensional array called MPA that will store and organize cadet MPA's ratings according to the following scheme:
The first index will vary from 1-40 and represent which squadron the cadet is in.
The second index will vary from 1-4 and represent which class (firstie, 2-degree, 3-degree, 4-degree) the cadet is in.
The third index will vary from 1-20 and specify which element the cadet is in.
The fourth index will vary from 1-10 and uniquely identify the cadet within their element.
This 4-dimensional array requires that 4 values be used
to access an individual cadet's MPA rating. For example,
MPA(18, 2, 3, 5) would store the value for a cadet in
squadron 18, who is the 5th cadet in element 3 and is a 2-degree.
Assign a random value in the range [0.0,4.0] to each element of the MPA
array.
Print out all the MPA rating values for your squadron from this array.
Print out all the MPA rating values for every 2-degree in the 2nd group.
Add a comment to your code that states whether this organization of MPA values into a 4-dimensional array makes sense to you. Would you rather store all the values in a single-dimensional vector? Why or why not?
Place one or more lines of comments at the bottom of your lab20()function and document the memory usage for your variables and the percentage of memory that was saved by the sparse matrices.
Turn-in:
Submit your lab20.m file.