




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





I. Terminating Condition II. Calling a clone of the function III. Iteration IV. Infinite Loop V. Matrix Manipulation A. I only B. III only C. IV only D. I and II E. III, IV, and V
What is the value of c? A. [8 10 9 B. [18 16 8 C. [9 2 5 D. [13 16 13 E. Error 10 6 13 4 6 12 10 6 13 8 6 8 9 13 6 ] 10 14 6] 9 13 6 ] 8 14 8 ]
A. B.
E. None of the above
Based on the code above, in which axis is the function rotated? A. x-axis B. y-axis C. z-axis D. None of the above E. Error
What is the final value of H? A. hw: {[15 15] {18,18} [15 15]} OGG: 18 B. 1x2 struct array C. hw: {[15 15] {{15,15},18} 100} OGG: {15,15} D. 2x1 struct array E. Error
G = [9 4 3; 1 4 2; 7 6 3]; H = [G G(end:-1:1,3)]; J = [H; H(1,:)]; K = sum(J);
What values are stored in variable K after all of the code above has been executed? A. [23 13 19 23] B. [26 18 11 11] C. [19 9 19 19] D. [26 18 11 23] E. None of the above
A. Consider the following function aRock:
function [type, group] = aRock(structval) ff = fieldnames(structval); if length(ff) >= 3 type = 1; group = 'coolRock'; else type = 3; group = aRockstar(structval); end
function group = aRockstar(structval) gg = fieldnames(structval); if length(gg) == 3 group = 'madeItAt'; else val = structval(end).(gg{end}); structval(end+1).(val) = 0; group = [aRockstar(structval) gg{end}]; end
The following lines are run in the command window of Matlab:
value = struct('name',{'bob','cod','eric'},'last',{'singh','patel','jiva'}) [second, first] = aRock(value)
A. [name last] B. {'name', 'last'} C. ['name'; 'last']
D. {'name'; 'last'} E. Error
A. 1 B. 0 C. 3 D. 2 E. Error
A. {'name' 'last' 'jiva'} B. {'name'; 'last'; 'last'}
C. {'name'; 'last'; 'jiva'} D. ['name'; 'last' ; 'jiva'] E. None of the above
A. 'coolRock' B. 'madeItAt' C. 'madeItAtlast' D. 'lastmadeItAt'
E. None of the above
A. 0 B. 1 C. 2 D. 3 E. 4
You have created a structure array with information about all the mp3 files in your music folder. Your array has fields containing the following: o the filename (a string) o album (a string) o artist (a string) o song length (in minutes) (a double) o a rating from 1 to 5 (5 being the best) (a double)
The following is a list of possible algorithm steps. For each of the three functions described below, write the letters of the necessary steps in order. Steps will not be used more than once within the same function, but they may be used in more than one function. Not all steps will be used. Note: it may help to determine the necessary steps for each function, and then put them in order.
A. Find structure with maximum song length B. Check value in the proper field against input value C. Find all songs with rating D. Subtract song length from playlist length (if needed) E. Remove structure from input F. Initialize output G. Check artist field with input value
H. Check difference between song length and playlist length I. Find maximum rating J. Concatenate structure to output (if needed) K. Remove field from structure L. Check filename M. Use iteration N. Randomly select one song with rating
Function 1: FilterMusic FilterMusic should take in the music structure array, a field (artist, album, etc.), and a value for that field (specific artist/album, etc). The function should remove any structures in the array which have that value for the input field and then return the modified structure array.
Function 2: TimedPlaylist TimedPlaylist takes in the structure array and the number of minutes you would like your playlist to last. The function will return a structure array of the songs to be played. (Note: the number of minutes the songs play for may not exactly match the input amount. In this case, the playlist should be shorter than the input time, however, this difference should not be greater than the play time of the shortest song. Each song may only be included once.)
Function 3: RatedPlaylist The final function takes in the structure array and the number of songs you would like in the playlist. The function will return a structure array of the songs to be played. The function should add songs to the playlist based on rating โ all songs with the highest rating should be added first, then all songs with the next highest rating, and so forth until the input number of songs has been reached. However, the function should randomly choose among songs with the same rating, and each song should only be included once.
Choose ONE of the following two problems:
Problem A Write a function called RecursiveMin which recursively finds the minimum value in a given vector. You may NOT use the min() function to do this, and you MUST use recursion to receive credit.
function ret = RecursiveMin(vec)
if isempty(vec) ret = []; elseif length(vec) == 1 ret = vec; elseif vec(1) <= vec(end) ret = RecursiveMin(vec(1:end-1)); else ret = RecursiveMin(vec(2:end)); end
Problem B Write a function called xlsStruct that takes in an Excel file and returns a structure array. The first row of the Excel file will contain the title of each column (i.e., Name, Age, Score, etc). Each row beneath that will contain actual data and information. Your function should create a structure array with fieldnames corresponding to the titles in that first row, and the function should then create a structure by filling in the fields for each row of data.
function SA = xlsStruct(filename)
[num txt raw] = xlsread(filename); [row col] = size(raw); for ind1 = 2:row for ind2 = 1:col SA(ind1-1).(raw{1, ind2}) = raw{ind1, ind2}; end end