1.
normal
2.
poisson
3.
binomial
4.
uniform
Q 1 / 64
a = rand(1, 11); b = sort(a); c = b(1, ceil(end/2));
1.
median
2.
mode
3.
mean
4.
margin
Q 2 / 64
1.
execution time
2.
command history
3.
errors
4.
the value of variables
Q 3 / 64
a = 0; do a = a + 1; while a < 5 end a = 0; while(a < 5) a = a + 1; a = 0; while a < 5: a = a + 1; a = 0; while a < 5 a = a + 1; end
1.
a = 0;
do
a = a + 1;
while a < 5
end
2.
a = 0;
while(a < 5)
a = a + 1;
3.
a = 0;
while a < 5:
a = a + 1;
4.
a = 0;
while a < 5
a = a + 1;
end
Q 4 / 64
a = 19 20 12 0 6 6 9 56 0 3 46 8 9 8 19 9 8 8 19 46 1 9 46 6 19 b = 56 0 9 8 b = 8 19 19 46
1.
b =
56 0
9 8
2.
b =
8 19
19 46
Q 5 / 64
t = cputime(myfun()); tic; myfun(); toc; timer.start; myfun() t = timer.stop; t = timer(myfun());
1.
t = cputime(myfun());
2.
tic;
myfun();
toc;
3.
timer.start;
myfun()
t = timer.stop;
4.
t = timer(myfun());
Q 6 / 64
1.
argument placeholder
2.
block quotes
3.
code sections
4.
conversion specifier
Q 7 / 64
1.
structure field access
2.
a decimal point
3.
cell array access
4.
element-wise operations
Q 8 / 64
1.
polyval
2.
regress
3.
solve
4.
polyfit
Q 9 / 64
1.
[0 1 1 1 2]
2.
[1 3 5 5 6]
3.
[0 1 1 1 1]
4.
[0 0 5 5 5]
Q 10 / 64
x = [-1:0.1:1]; y = X.^2; plot(x, y)
1.
Your plot doesn't plot in a figure window because `figure` was not called immediately in advance.
2.
Your `plot` syntax is incorrect.
3.
Your plot is in a figure window that was already open, hidden behind other windows on your screen.
4.
Your plot was saved to an image file but not displayed.
Q 11 / 64
1.
S['name']
2.
S.name
3.
S('name')
4.
S{'name'}
Q 12 / 64
1.
basic imaginary unit
2.
index function
3.
infinity
4.
index variable
Q 13 / 64
a = [1 2 3; 4 5 6]; 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; end end
1.
b = a*a;
2.
b = a.^2;
3.
b = a^2;
4.
b = pow2(a);
Q 14 / 64
1.
xticks(-3*pi:3.14:3*pi)
2.
xticks(-3*pi:pi:3*pi)
3.
xticks(linespace(-3*pi(), 3*pi(), pi()))
4.
xticks(linespace(-3*pi, 3*pi, pi)
Q 15 / 64
a = ones(1,3); b = 1:3; c = conv(a,b)
1.
[-1 2 -1]
2.
[1 3 6 5 3]
3.
6
4.
[1 -2 1]
Q 16 / 64
1.
datasample
2.
randi
3.
resample
4.
randperm
Q 17 / 64
x = 7; switch x case 2 disp("two"); otherwise disp("not two"); end x = 7; switch x : case 2 disp("two"); otherwise disp("not two"); end x = 7; switch x case 2 disp("two"); else disp("not two"); end x = 7; switch x case 2 disp("two"); default disp("not two"); end
1.
x = 7;
switch x
case 2
disp("two");
otherwise
disp("not two");
end
2.
x = 7;
switch x :
case 2
disp("two");
otherwise
disp("not two");
end
3.
x = 7;
switch x
case 2
disp("two");
else
disp("not two");
end
4.
x = 7;
switch x
case 2
disp("two");
default
disp("not two");
end
Q 18 / 64
a = 1; b = 2; c = 3; d = 4; e = c / (~a - b == c - d); c = NaN c = Inf c = -0.2500
1.
c =
NaN
2.
c =
Inf
3.
c =
-0.2500
Q 19 / 64
1.
When you pass a handle object to a function, a new object is made that is independent of the original.
2.
All copies of handle objects refer to the same underlying object.
3.
Handle object cannot reference one another.
4.
Handle object do not have a default `eq` function.
Q 20 / 64
f10 = 1; for i = 1:10 f10 = f10 * i; end `f10 = factorial(10)` MATLAB f10 = 1; i = 1; while i <= 10 i = i + 1; f10 = i * f10; end `f10 = prod(1:10)`
1.
f10 = 1;
for i = 1:10
f10 = f10 * i;
end
2.
undefined
3.
MATLAB
f10 = 1;
i = 1;
while i <= 10
i = i + 1;
f10 = i * f10;
end
4.
undefined
Q 21 / 64
a = rand(5); round(a * inv(a)) `diag(ones(5, 1))` `identity(5)` `eye(5)`
1.
a = rand(5);
round(a * inv(a))
2.
undefined
3.
undefined
4.
undefined
Q 22 / 64
dog = name: 'Bindy' breed: 'border collie' weight: 32 `dog = struct('name', 'Bindy'; 'breed', 'border collie'; 'weight', 32);` dog.name = 'Bindy'; dog.breed = 'border collie'; dog.weight = 32; dog = { 'name' : 'Bindy', 'breed' : 'border collie', 'weight': 32; } dog('name') = 'Bindy'; dog('breed') = 'border collie'; dog('weight') = 32;
1.
undefined
2.
dog.name = 'Bindy';
dog.breed = 'border collie';
dog.weight = 32;
3.
dog = {
'name' : 'Bindy',
'breed' : 'border collie',
'weight': 32;
}
4.
dog('name') = 'Bindy';
dog('breed') = 'border collie';
dog('weight') = 32;
Q 23 / 64
function a = my_func(a) a = a + 1; end a = 0; for i = 1:3 my_func(a); end a = my_func(a);
1.
undefined
2.
4
3.
3
4.
0
5.
1
Q 24 / 64
c = {["hello world"]} {1×1 cell} {["goodbye"]} {1×3 double}
1.
c = {"hello world" {"hello"} "goodbye" [1 2 ]};
2.
c = {"hello world" {"hello"} "goodbye" {[1 2 3]}};
3.
c = {"hello world" {"hello"} "goodbye" [1 2 3]};
4.
c = {"hello world" {"hello" "hello"} "goodbye" {[1 2 3]}};
Q 25 / 64
a = ones(4, 4); b= [1 2 3 4];
1.
a = a + reshape(b, 4, 1);
2.
a = a + b';
3.
a = a + repmat(b, 4, 1);
4.
a = a + [b b b b];
Q 26 / 64
for i = 1:length(fruit) fruit{i}(fruit{i} == a) == o; end for i = 1:length(fruit) fruit(i)(fruit(i) == 'a') == 'o'; end for i = 1:length(fruit) fruit{i}(fruit{i} == 'a') == 'o'; end for i = 1:length(fruit) fruit{i}(fruit{i} == 'a') == 'o';
1.
for i = 1:length(fruit)
fruit{i}(fruit{i} == a) == o;
end
2.
for i = 1:length(fruit)
fruit(i)(fruit(i) == 'a') == 'o';
end
3.
for i = 1:length(fruit)
fruit{i}(fruit{i} == 'a') == 'o';
end
4.
for i = 1:length(fruit)
fruit{i}(fruit{i} == 'a') == 'o';
Q 27 / 64
1.
poly([1 2 -4])
2.
solve(x^2 + 2x - 4 == 0)
3.
polyfit(x^2 + 2x - 4 == 0)
4.
roots([1 2 -4])
Q 28 / 64
1.
C = {C a};
2.
C = cellcat(C a)
3.
C = cat(2, {a}, C)
4.
C{end+1}=a
Q 29 / 64
1.
sim_height = std(height) + mean(height) * randn(100, 1);
2.
sim_height = mean(height) + std(height) * randn(100, 1);
3.
sim_height = randn(std(height), mean(height), [100, 1]);
4.
sim_height = randn(mean(height), std(height), [100, 1]);
Q 30 / 64
`menu = {'hot dog' 'corn dog' 'regular burger' 'cheeseburger' 'veggie burger'}`
1.
menu{strfind(menu, 'burger')}
2.
menu(strfind(menu, 'burger'))
3.
menu{contains(menu, 'burger')}
4.
menu(contains(menu, 'burger'))
Q 31 / 64
a = randi(10, [1, 10]); a(3) = 11; a(a>2) = 12;
1.
3, 4, 5, 6, 7, 8, 9, 10, 11, 12
2.
1, 2, 12
3.
2, 11, 12
4.
1, 12
Q 32 / 64
1.
You can use the `sparse` function to remove empty cells from cell array variables.
2.
Sparse matrices always use less memory than their associated full matrices.
3.
Mixtures of sparse and full matrices can be combined in all of MATLAB's built-in arithmetic operations.
4.
The `sparse` function requires its input to be a full matrix with at least 50% zero elements.
Q 33 / 64
`a = 1:10;`
1.
b = a(a ~= 11)
2.
b = a(a == 1)
3.
b = a(a>6 && a<9)
4.
b = a(a | 1)
Q 34 / 64
menu = {'hot dog' 'corn dog' 'regular burger' 'cheeseburger' 'veggie burger'} menu_string = 'hot dog corn dog regular burger cheeseburger veggie burger'
1.
menu_string = cell2mat(join(menu, newline))
2.
menu_string = cell2mat(join(menu, 'n'))
3.
menu_string = join(menu, newline)
4.
menu_string = cell2mat(pad(menu))
Q 35 / 64
`rng_settings_curr = rng('shuffle');` rng(time()); rng_settings_curr = rng(); `rng_settings_curr = rand('shuffle');` rng('shuffle'); rng_settings_curr = rng();
1.
undefined
2.
rng(time());
rng_settings_curr = rng();
3.
undefined
4.
rng('shuffle');
rng_settings_curr = rng();
Q 36 / 64
`data_nomean = data - repmat(median(data), size(data, 1), 1);` `data_nomean = bsxfun(@minus, data, mean(data));` data_nomean = zeros(size(data)); for i = 1:size(data, 1) data_nomean(i, :) = data(i, :) - mean(data(i, :)); end `data_nomean = zscore(data');`
1.
undefined
2.
undefined
3.
data_nomean = zeros(size(data));
for i = 1:size(data, 1)
data_nomean(i, :) = data(i, :) - mean(data(i, :));
end
4.
undefined
Q 37 / 64
b = zeros(1, size(C, 2)); for i_C = 1:size(C, 2) b(i_C) = mean(C(i_C)); end `b = cellfun(@mean, C);` b = zeros(1, size(C, 1)); for i_C = 1:size(C, 1) b(i_C) = mean(C{i_C}(:)); end `b = cellfun(@(m) mean(m(:)), C)`
1.
b = zeros(1, size(C, 2));
for i_C = 1:size(C, 2)
b(i_C) = mean(C(i_C));
end
2.
undefined
3.
b = zeros(1, size(C, 1));
for i_C = 1:size(C, 1)
b(i_C) = mean(C{i_C}(:));
end
4.
undefined
Q 38 / 64
`passwords = {'abcd' '1234' 'qwerty' 'love1'};`
1.
contains(password, 'd')
2.
~isempty(regexp(passwords, 'd'))
3.
cellfun(@(x) ~isempty(regexp(x, 'd')), passwords)
4.
regexp(passwords, 'd')
Q 39 / 64
1.
title
2.
text
3.
label
4.
legend
Q 40 / 64
![MatLab Q39](images/matlab_Q39.jpg) figure x = rand(10,10); r = corrcoef(x); surf(r) colorbar figure x = rand(10,10); r = corrcoef(x); imagesc(r) colorbar
1.
figure
x = rand(10,10);
r = corrcoef(x);
surf(r)
colorbar
2.
figure
x = rand(10,10);
r = corrcoef(x);
imagesc(r)
colorbar
Q 41 / 64
1.
figure files
2.
script files
3.
function files
4.
stored variable files
Q 42 / 64
`a = 1:10;` `b = a(randi(10, 1, 10));` m = perms(a); i = randi(factorial(10), 1); b = a(m(i, :)) b = a(i); b = a(randperm(10));
1.
undefined
2.
m = perms(a);
i = randi(factorial(10), 1);
b = a(m(i, :))
3.
[s, j] = sort(rand(10, 1));
b = a(i);
4.
b = a(randperm(10));
Q 43 / 64
a = 'stand' b = "stand"
1.
a == b
2.
ischar(b)
3.
length(a) == length(b)
4.
class(a) == class(b)
Q 44 / 64
C = {'dog' 'cat' 'mouse'} D = {'cow' 'piranha' 'mouse'} E = setdiff(C,D)
1.
E = {'cat'} {'dog'}
2.
E = {'mouse'}
3.
E = {'cat'} {'cow'} {'dog'} {'piranha'}
4.
E =
Q 45 / 64
1.
Editor
2.
command window
3.
details
4.
workspace
Q 46 / 64
x = 9.0646 6.4362 7.8266 8.3945 5.6135 4.8186 2.8862 10.9311 1.1908 3.2586 y = 15.4357 11.0923 14.1417 14.9506 8.7687 8.0416 5.1662 20.5005 1.0978 coeff_line = polyfit(x,y,1) x_line = floor(min(x)):0.1:ceil(max(x)); y_line = polyval(coeff_line,x_line) figure; plot(x,y,'o') hold on plot(x_linemy_line) figure plot(x,y,'o') coeff_line = polyfit(x,y,1); x_line = floor(min(x)):0.1:ceil(max(x)); y_line = polyval(coeff_line,x_line); plot(x_line,y_line) figure plot(x,y) coeff_line = polyfit(x,y,1); x_line = floor(min(x)):0.1:ceil(max(x)); y_line = polyval(coeff_line,x_line); hold on; plot(x_line,y_line) coeff_line = polyfit(x,y,1); x_line = floor(min(x)):0.1:ceil(max(x)); y_line = polyval(coeff_line,x_line); figure; plot(x,y,'o') hold on plot(x_line,y_line)
1.
coeff_line = polyfit(x,y,1)
x_line = floor(min(x)):0.1:ceil(max(x));
y_line = polyval(coeff_line,x_line)
figure; plot(x,y,'o')
hold on
plot(x_linemy_line)
2.
figure
plot(x,y,'o')
coeff_line = polyfit(x,y,1);
x_line = floor(min(x)):0.1:ceil(max(x));
y_line = polyval(coeff_line,x_line);
plot(x_line,y_line)
3.
figure
plot(x,y)
coeff_line = polyfit(x,y,1);
x_line = floor(min(x)):0.1:ceil(max(x));
y_line = polyval(coeff_line,x_line);
hold on; plot(x_line,y_line)
4.
coeff_line = polyfit(x,y,1);
x_line = floor(min(x)):0.1:ceil(max(x));
y_line = polyval(coeff_line,x_line);
figure; plot(x,y,'o')
hold on
plot(x_line,y_line)
Q 47 / 64
a = [0 1 2 3; 4 5 6 7]; a = a^2;
1.
You are attempting to multiply a non-square matrix by itself, causing a dimension mismatch.
2.
MATLAB does not allow you to square all the elements in the matrix in a single operation.
3.
You must use the ** operator instead of the ^ operator.
4.
You cannot square matrices that have a 0 as the first element.
Q 48 / 64
1.
v = {1:10}
2.
v = [1-10]
3.
v = 1:10
4.
v = (10)
Q 49 / 64
1.
7
2.
8
3.
17
4.
9
Q 50 / 64
1.
Global variables have a higher performance overhead than persistent variables.
2.
Global variables remain in memory after clear all; persistent variables do not.
3.
Global variables can be used to cache data in memory; persistent variables cannot.
4.
Global variables are accessible outside the function scope; persistent variables are not.
Q 51 / 64
1.
Seed is undefined until it is initialized by the user.
2.
Seed is set to a value based on the current time when user first calls rand()
3.
Seed is set to a value based on the current time on startup.
4.
Seed is set to a static default value on startup.
Q 52 / 64
1.
functions on the path
2.
built-in functions
3.
functions within the current file
4.
functions within the current directory
Q 53 / 64
function mystery_func(a) : return a function b = mystery_func(a) b = a; end def b = mystery_func(a) b = a; end function mystery_func(a) b = a; return b; end
1.
function mystery_func(a) :
return a
2.
function b = mystery_func(a)
b = a;
end
3.
def b = mystery_func(a)
b = a;
end
4.
function mystery_func(a)
b = a;
return b;
end
Q 54 / 64
a = [1 2; 3 4]; b = a(:,2); c = b + 3; a(1:2,1) = c; a = 6 3 7 4 a = 5 2 7 4 a = 5 7 a = 6 7
1.
a =
5 2
7 4
2.
a =
5
7
3.
a =
6
7
4.
undefined
Q 55 / 64
1.
`h_f = figure; set(h_f,'Color', [0 0 0]);`
2.
`h_a = gca; set(h_a,'Color', [0 0 0]);`
3.
`h_a = axes; set(h_a,'Color', [0 0 0]);`
4.
`h_f = gcf; set(h_a,'Color', [0 0 0]);`
Q 56 / 64
1.
`2*[1:5]+1`
2.
`1:2:9`
3.
`isodd(1:9)`
4.
`1:odd:9`
Q 57 / 64
h = ones(5,5)/25; imshow(imfilter(img,h));
1.
`h` is a Gaussian filter that adds to 1. Its intended effect is to highlight image edges.
2.
`h` is an averaging filter uniformly distributed that adds to 1. Its intended effect is to smooth out images (remove noise).
3.
`h` is a Laplacian filter that adds up to 0. Its intended effect is to smooth out images (remove noise).
4.
`imfilter` is a function that always blurs the images.
Q 58 / 64
a = [1 2 3]; b = repmat(a,2,3);
1.
1x3
2.
3x2
3.
2x3
4.
2x9
Q 59 / 64
a = [ 1 2 3 4];
1.
reverse(a)
2.
a(end:- 1:1)
3.
rev(a)
4.
a(::-1)
Q 60 / 64
1.
`c = [7,8,9]`
2.
`c = [7: 8: 9]`
3.
`c = [7; 8; 9]`
4.
`c = [7 8 9]`
Q 61 / 64
1.
`who`
2.
`vars`
3.
`whos`
4.
`who all`
Q 62 / 64
1.
which
2.
who
3.
lookfor
4.
what
Q 63 / 64
1.
to ensure backward compatibility
2.
to avoid HDF5 overhead in MAT-file
3.
to include a variable greater that 2GB
4.
to use compression by default
Q 64 / 64