Q1. From what distribution does the rand() function return value?
normal
poisson
binomial
uniform
Q2. Based on the code below, c is the _ of a.
a =rand(1,11);
b =sort(a);
c =b(1,ceil(end/2));
median
mode
mean
margin
Q3. What does the Profiler track?
execution time
command history
errors
the value of variables
Q4. Which code block contains the correct syntax for a while loop?
[ ]
a =0;
do
a = a +1;while a <5end
[ ]
a =0;while(a <5)
a = a +1;
[ ]
a =0;while a <5:
a = a +1;
[x]
a =0;while a <5
a = a +1;end
Q5. What does b contain?
a =19201206695603468981998819461946619
[x]
b =56098
[ ]
b =8191946
Q6. You have written a function myfun and want to measure how long it takes to run. Which code segment will return in t the time in seconds it takes myfun to run?
[ ]
t =cputime(myfun());
[x]
tic;myfun();
toc;
[ ]
timer.start;myfun()
t = timer.stop;
[ ]
t =timer(myfun());
Q7. What is %% used for?
argument placeholder
block quotes
code sections
conversion specifier
Q8. what is the . character NOT used for?
structure field access
a decimal point
cell array access
element-wise operations
Q9. Which function could you use for multiple linear regression?
polyval
regress
solve
polyfit
Q10. For which of these arrays do mean, median, and mode return the same value?
[0 1 1 1 2]
[1 3 5 5 6]
[0 1 1 1 1]
[0 0 5 5 5]
Q11. You are in the middle of a long MATLAB session where you have performed many analyses and made many plots. You run the following commands, yet a figure window doesn't pop up on the top of your screen with your plot. What might be the issue?
x =[-1:0.1:1];
y = X.^2;plot(x, y)
Your plot doesn't plot in a figure window because figure was not called immediately in advance.
Your plot syntax is incorrect.
Your plot is in a figure window that was already open, hidden behind other windows on your screen.
Your plot was saved to an image file but not displayed.
Q12. How do you access the value for the field name in structure S?
Q14. Which statement is equivalent to this for loop?
a =[123;456];
b =zeros(size(a));for i_row =1:size(a,1)for i_col =1:size(a,2)b(i_row, i_col)=a(i_row, i_col)^2;endend
b = a*a;
b = a.^2;
b = a^2;
b = pow2(a);
Q15. You have plotted values of cosine from -10 to 10 and want to change the x-axis tick marks to every pi, from -3pi to 3pi. Which statement will do that?
xticks(-3pi:3.14:3pi)
xticks(-3pi:pi:3pi)
xticks(linespace(-3pi(), 3pi(), pi()))
xticks(linespace(-3pi, 3pi, pi)
Q16. What is the value of c?
a =ones(1,3);
b =1:3;
c =conv(a,b)
[-1 2 -1]
[1 3 6 5 3]
6
[1 -2 1]
Q17. Which function CANNOT be used to randomly sample data?
datasample
randi
resample
randperm
Q18. Which choice is correct syntax for a switch statement?
[x]
x =7;switch x
case2disp("two");otherwisedisp("not two");end
[ ]
x =7;switch x :case2disp("two");otherwisedisp("not two");end
[ ]
x =7;switch x
case2disp("two");elsedisp("not two");end
[ ]
x =7;switch x
case2disp("two");
default
disp("not two");end
Q19. What is the result of this code?
a =1;
b =2;
c =3;
d =4;
e = c /(~a - b == c - d);
Error
[ ]
c =NaN
[x]
c =
Inf
[ ]
c =-0.2500
Q20. What is true of a handle class object?
When you pass a handle object to a function, a new object is made that is independent of the original.
All copies of handle objects refer to the same underlying object.
Handle object cannot reference one another.
Handle object do not have a default eq function.
Q21. Which choice has a different final result in f10 than the other three?
[ ]
f10 =1;fori=1:10
f10 = f10 *i;end
[ ]
f10 =factorial(10)
[x]
f10 =1;i=1;whilei<=10i=i+1;
f10 =i* f10;end
[ ]
f10 =prod(1:10)
Q22. Which choice will NOT give you a 5 x 5 identity matrix?
[ ]
a =rand(5);round(a *inv(a))
[ ]
diag(ones(5,1))
[x]
identity(5)
[ ]
eye(5)
Q23. Which statement creates this structure?
dog =
name:'Bindy'
breed:'border collie'
weight:32
[ ]
dog =struct('name','Bindy';'breed','border collie';'weight',32);
Q28. Which statement returns the roots for the polynomial x^2 + 2x - 4?
poly([1 2 -4])
solve(x^2 + 2x - 4 == 0)
polyfit(x^2 + 2x - 4 == 0)
roots([1 2 -4])
Q29. Which choice is the proper syntax to append a new elements a to the end of 1x 2 dimensional cell array C?
C = {C a};
C = cellcat(C a)
C = cat(2, {a}, C)
C{end+1}=a
Q30. You have loaded a dataset of people's heights into a 100 x 1 array called height. Which statement will return a 100 x 1 array, sim_height, with values from a normal distribution with the same mean and variance as your height data?
Q31. Which statement returns a cell array of the strings containing 'burger' from menu?
menu ={'hot dog''corn dog''regular burger''cheeseburger''veggie burger'}
menu{strfind(menu, 'burger')}
menu(strfind(menu, 'burger'))
menu{contains(menu, 'burger')}
menu(contains(menu, 'burger'))
Q32. What is the set of possible values that a may contain?
a =randi(10,[1,10]);a(3)=11;a(a>2)=12;
3, 4, 5, 6, 7, 8, 9, 10, 11, 12
1, 2, 12
2, 11, 12
1, 12
Q33. Which statement is true about the sparse matrices?
You can use the sparse function to remove empty cells from cell array variables.
Sparse matrices always use less memory than their associated full matrices.
Mixtures of sparse and full matrices can be combined in all of MATLAB's built-in arithmetic operations.
The sparse function requires its input to be a full matrix with at least 50% zero elements.
Q34. Which statement using logical indices will result in an error?
a =1:10;
b = a(a ~= 11)
b = a(a == 1)
b = a(a>6 && a<9)
b = a(a | 1)
Q35. Which statement turns menu into the variable menu_string below?
menu ={'hot dog''corn dog''regular burger''cheeseburger''veggie burger'}
menu_string ='hot dog
corn dog
regular burger
cheeseburger
veggie burger'
menu_string = cell2mat(join(menu, newline))
menu_string = cell2mat(join(menu, '\n'))
menu_string = join(menu, newline)
menu_string = cell2mat(pad(menu))
Q36. Which code snippet sets a new random seed based on the current time and saves the current settings of the random number generator?
[x]
rng_settings_curr =rng('shuffle');
[ ]
rng(time());
rng_settings_curr =rng();
[ ]
rng_settings_curr =rand('shuffle');
[ ]
rng('shuffle');
rng_settings_curr =rng();
Q37. You have a matrix data in which each column is mono audio recording from a room in your house. You've noticed that each column has a very different mean and when you plot them all on the same graph, the spread across the y axis make it impossible to see anything. You want to subtract the mean from each column. Which code block will accomplish this?
[ ]
data_nomean = data -repmat(median(data),size(data,1),1);