0% found this document useful (0 votes)
9 views

MATLAB _ linkedin-skill-assessments-quizzes

The document contains a series of MATLAB-related quiz questions covering topics such as random number generation, data manipulation, syntax, and functions. It includes questions about specific MATLAB functions, code syntax, and the behavior of various programming constructs. The format suggests it is designed for assessing knowledge of MATLAB programming skills.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

MATLAB _ linkedin-skill-assessments-quizzes

The document contains a series of MATLAB-related quiz questions covering topics such as random number generation, data manipulation, syntax, and functions. It includes questions about specific MATLAB functions, code syntax, and the behavior of various programming constructs. The format suggests it is designed for assessing knowledge of MATLAB programming skills.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

B

linkedin-skill-assessments-quizzes a = 0;
while(a < 5)
a = a + 1;
MATLAB
C
Q1. From what distribution does the rand() function return value?

a = 0;
normal
while a < 5:
poisson a = a + 1;
binomial
uniform D

Q2. Based on the code below, c is the _ of a.


a = 0;
while a < 5
a = rand(1, 11); a = a + 1;
b = sort(a); end
c = b(1, ceil(end/2));

Q5. What does b contain?


median
mode
a =
mean 19 20 12 0 6
6 9 56 0 3
margin
46 8 9 8 19
9 8 8 19 46
Q3. What does the Profiler track? 1 9 46 6 19

execution time
command history A

errors
b =
the value of variables
56 0
Reference
9 8

Q4. Which code block contains the correct syntax for a while loop?
B
A

b =
a = 0;
do 8 19
a = a + 1; 19 46
while a < 5
end

Q6. You have written a function myfun and want to measure how long it takes to run. Which polyfit
code segment will return in t the time in seconds it takes myfun to run?
Q10. For which of these arrays do mean , median , and mode return the same value?
A
[0 1 1 1 2]
t = cputime(myfun()); [1 3 5 5 6]
[0 1 1 1 1]
A [0 0 5 5 5]

tic; Q11. You are in the middle of a long MATLAB session where you have performed many
myfun(); analyses and made many plots. You run the following commands, yet a figure window doesn’t
toc; pop up on the top of your screen with your plot. What might be the issue?

x = [-1:0.1:1];
C
y = X.^2;
plot(x, y)
timer.start;
myfun()
t = timer.stop; Your plot doesn’t plot in a figure window because figure was not called immediately in
advance.
Your plot syntax is incorrect.
D
Your plot is in a figure window that was already open, hidden behind other windows on
your screen.
t = timer(myfun());
Your plot was saved to an image file but not displayed.

Q7. What is %% used for? Q12. How do you access the value for the field name in structure S?

argument placeholder S[‘name’]


block quotes S.name
code sections S(‘name’)
conversion specifier S{‘name’}

Q8. what is the . character NOT used for? Q13. What built-in definition does i have?

structure field access basic imaginary unit


a decimal point index function
cell array access infinity
element-wise operations index variable

Q9. Which function could you use for multiple linear regression? Q14. Which statement is equivalent to this for loop?

polyval
a = [1 2 3; 4 5 6];
regress b = zeros(size(a));
solve 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; disp("not two");
end end
end
B
b = a*a;
b = a.^2; x = 7;
b = a^2; switch x :
case 2
b = pow2(a); disp("two");
otherwise
Q15. You have plotted values of cosine from -10 to 10 and want to change the x-axis tick marks disp("not two");
to every pi, from -3pi to 3pi. Which statement will do that? end

xticks(-3pi:3.14:3pi)
C
xticks(-3pi:pi:3pi)
xticks(linespace(-3pi(), 3pi(), pi()))
x = 7;
xticks(linespace(-3pi, 3pi, pi) switch x
case 2
Q16. What is the value of c ? disp("two");
else
disp("not two");
a = ones(1,3);
end
b = 1:3;
c = conv(a,b)
D
[-1 2 -1]
x = 7;
[1 3 6 5 3]
switch x
6 case 2
[1 -2 1] disp("two");
default
disp("not two");
Q17. Which function CANNOT be used to randomly sample data? end

datasample
randi Q19. What is the result of this code?
resample
randperm a = 1;
b = 2;
c = 3;
Q18. Which choice is correct syntax for a switch statement?
d = 4;
e = c / (~a - b == c - d);
A

x = 7; Error
switch x B
case 2
disp("two");
otherwise c =

NaN
a = rand(5);
C round(a * inv(a))

c = B diag(ones(5, 1))
Inf
C identity(5)
D eye(5)
D
Q23. Which statement creates this structure?
c =
-0.2500 dog =

name: 'Bindy'
Q20. What is true of a handle class object? breed: 'border collie'
weight: 32
When you pass a handle object to a function, a new object is made that is independent of
the original.
A dog = struct('name', 'Bindy'; 'breed', 'border collie'; 'weight', 32);
All copies of handle objects refer to the same underlying object.
B
Handle object cannot reference one another.
Handle object do not have a default eq function.
dog.name = 'Bindy';
dog.breed = 'border collie';
Q21. Which choice has a different final result in f10 than the other three? dog.weight = 32;

A
C
f10 = 1;
for i = 1:10 dog = {
f10 = f10 * i; 'name' : 'Bindy',
end 'breed' : 'border collie',
'weight': 32;
}
B f10 = factorial(10)
C
D

f10 = 1;
i = 1; dog('name') = 'Bindy';
dog('breed') = 'border collie';
while i <= 10
i = i + 1; dog('weight') = 32;
f10 = i * f10;
end
Q24. my_func is a function as follows. What is the value of a at the end of the code
beneath?
D f10 = prod(1:10)
function a = my_func(a)
Q22. Which choice will NOT give you a 5 x 5 identity matrix? a = a + 1;
end
A ------------------
a = 0; C
for i = 1:3
my_func(a);
end for i = 1:length(fruit)
a = my_func(a); fruit{i}(fruit{i} == 'a') == 'o';
end
4
3 D
0
1 for i = 1:length(fruit)
fruit{i}(fruit{i} == 'a') == 'o';
Q25. Which statement could create this cell array?

c = {["hello world"]} {1×1 cell} {["goodbye"]} {1×3 double} Q28. Which statement returns the roots for the polynomial x^2 + 2x - 4 ?

c = {"hello world" {"hello"} "goodbye" [1 2 ]}; poly([1 2 -4])


c = {"hello world" {"hello"} "goodbye" {[1 2 3]}}; solve(x^2 + 2x - 4 == 0)
c = {"hello world" {"hello"} "goodbye" [1 2 3]}; polyfit(x^2 + 2x - 4 == 0)
c = {"hello world" {"hello" "hello"} "goodbye" {[1 2 3]}}; roots([1 2 -4])

Q26. Which choice adds b to each row of a ? Q29. Which choice is the proper syntax to append a new elements a to the end of 1x 2
dimensional cell array C ?

a = ones(4, 4); C = {C a};


b= [1 2 3 4];
C = cellcat(C a)
C = cat(2, {a}, C)
a = a + reshape(b, 4, 1);
C{end+1}=a
a = a + b’;
a = a + repmat(b, 4, 1); Q30. You have loaded a dataset of people’s heights into a 100 x 1 array called height . Which
a = a + [b b b b]; 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?
Q27. Which choice replaces all a s with o s?
sim_height = std(height) + mean(height) * randn(100, 1);
A sim_height = mean(height) + std(height) * randn(100, 1);
sim_height = randn(std(height), mean(height), [100, 1]);
for i = 1:length(fruit) sim_height = randn(mean(height), std(height), [100, 1]);
fruit{i}(fruit{i} == a) == o;
end
Q31. Which statement returns a cell array of the strings containing ‘ burger ’ from menu ?

B menu = {'hot dog' 'corn dog' 'regular burger' 'cheeseburger' 'veggie burger'}

menu{strfind(menu, ‘burger’)}
for i = 1:length(fruit)
menu(strfind(menu, ‘burger’))
fruit(i)(fruit(i) == 'a') == 'o';
end menu{contains(menu, ‘burger’)}
menu(contains(menu, ‘burger’))

Q32. What is the set of possible values that a may contain? Q36. Which code snippet sets a new random seed based on the current time and saves the
current settings of the random number generator?
a = randi(10, [1, 10]); rng_settings_curr = rng('shuffle');
a(3) = 11;
a(a>2) = 12; B

rng(time());
3, 4, 5, 6, 7, 8, 9, 10, 11, 12
rng_settings_curr = rng();
1, 2, 12
2, 11, 12
C rng_settings_curr = rand('shuffle');
1, 12
D

Q33. Which statement is true about the sparse matrices?


rng('shuffle');
You can use the sparse function to remove empty cells from cell array variables. rng_settings_curr = rng();

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 Q37. You have a matrix data in which each column is mono audio recording from a room in
operations. your house. You’ve noticed that each column has a very different mean and when you plot
The sparse function requires its input to be a full matrix with at least 50% zero elements. 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?
Q34. Which statement using logical indices will result in an error? data_nomean = data - repmat(median(data), size(data, 1), 1);

a = 1:10; data_nomean = bsxfun(@minus, data, mean(data));

.
b = a(a ~= 11)
b = a(a == 1)
data_nomean = zeros(size(data));
b = a(a>6 && a<9) for i = 1:size(data, 1)
data_nomean(i, :) = data(i, :) - mean(data(i, :));
[ ] b = a(a 1) end

Q35. Which statement turns menu into the variable menu_string below? . data_nomean = zscore(data');

menu = {'hot dog' 'corn dog' 'regular burger' 'cheeseburger' 'veggie burger'} Q38. Which code block results in an array b containing the mean values of each array within
menu_string = C?
'hot dog
corn dog .
regular burger
cheeseburger
veggie burger' b = zeros(1, size(C, 2));
for i_C = 1:size(C, 2)
b(i_C) = mean(C(i_C));
menu_string = cell2mat(join(menu, newline)) end

menu_string = cell2mat(join(menu, ‘\n’))


menu_string = join(menu, newline) . b = cellfun(@mean, C);
menu_string = cell2mat(pad(menu)) .
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)

Q39. Which statement creates a logical array that is 1 if the element in passwords contains a
digit and 0 if it does not?

passwords = {'abcd' '1234' 'qwerty' 'love1'};

contains(password, ‘\d’)
~isempty(regexp(passwords, ‘\d’))
cellfun(@(x) ~isempty(regexp(x, ‘\d’)), passwords)
regexp(passwords, ‘\d’)

Q40. Which is NOT a function that adds text to a plot?

title
text
label
legend

Q41. Which code block most likely produced this graph?


figure
x = rand(10,10);
r = corrcoef(x);
surf(r)
colorbar

figure
x = rand(10,10);
r = corrcoef(x);
imagesc(r)
colorbar

Q42. What kind of files are stored with the .mat extension?

figure files
script files
function files

stored variable files E=

Q43. You would like to randomly reorder every element in array a and put the result into Q46. Where in the UI can you see what variables have been created, their values, and their
another array b. Which code is NOT necessary to do that? class?

a = 1:10; Editor
command window
: b = a(randi(10, 1, 10));
details
:
workspace

m = perms(a);
Q47. Given the following x and y coordinates, which choice calculates a linear regression for
i = randi(factorial(10), 1);
the x and y coordinates, and which plots the points of the x,y data and the regression line on
b = a(m(i, :))
the same graph?

: 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
[s, j] = sort(rand(10, 1));
b = a(i);
:

: coeff_line = polyfit(x,y,1)
x_line = floor(min(x)):0.1:ceil(max(x));
y_line = polyval(coeff_line,x_line)
b = a(randperm(10));

figure; plot(x,y,'o')
hold on
Q44. Which statement returns 1 (true)?
plot(x_linemy_line)

a = 'stand'
b = "stand" :

figure
a == b
plot(x,y,'o')
ischar(b)
length(a) == length(b) coeff_line = polyfit(x,y,1);
x_line = floor(min(x)):0.1:ceil(max(x));
class(a) == class(b) y_line = polyval(coeff_line,x_line);
plot(x_line,y_line)
Q45. Which does E contain?

:
C = {'dog' 'cat' 'mouse'}
D = {'cow' 'piranha' 'mouse'}
E = setdiff(C,D) figure
plot(x,y)

E = {‘cat’} {‘dog’} coeff_line = polyfit(x,y,1);


x_line = floor(min(x)):0.1:ceil(max(x));
E = {‘mouse’}
E = {‘cat’} {‘cow’} {‘dog’} {‘piranha’}
y_line = polyval(coeff_line,x_line); Global variables are accessible outside the function scope; persistent variables are not.
hold on; plot(x_line,y_line)

Q52. How is the random seed for MATLAB’s random number generator first initializedin a
:
MATLAB Session?

coeff_line = polyfit(x,y,1); Seed is undefined until it is initialized by the user.


x_line = floor(min(x)):0.1:ceil(max(x)); Seed is set to a value based on the current time when user first calls rand()
y_line = polyval(coeff_line,x_line);
Seed is set to a value based on the current time on startup.
figure; plot(x,y,'o') Seed is set to a static default value on startup.
hold on
plot(x_line,y_line) Reference

Q53. At what will MATLAB look first for a called function?


Q48. If you run this piece of code, you will get an error. Why?
functions on the path
a = [0 1 2 3; 4 5 6 7]; built-in functions
a = a^2;
functions within the current file
functions within the current directory
You are attempting to multiply a non-square matrix by itself, causing a dimension
mismatch. Reference
MATLAB does not allow you to square all the elements in the matrix in a single operation.
Q54. Which choice is the correct syntax for declaring a function that returns the input value as
You must use the ** operator instead of the ^ operator.
the output?
You cannot square matrices that have a 0 as the first element.
:
Q49. Which command will create a 10-element vector v with values from 1 to 10?
function mystery_func(a) :
v = {1:10} return a
v = [1-10]
v = 1:10 :
v = (10)
function b = mystery_func(a)
Q50. For a 5 x 5 array, the two subscript index (4,2) indexes the same location as linear index b = a;
___ . end

7
8 :

17
def b = mystery_func(a)
9
b = a;
end
Q51. What is a difference between global variable and persistent variables?

Global variables have a higher performance overhead than persistent variables. :


Global variables remain in memory after clear all; persistent variables do not.
Global variables can be used to cache data in memory; persistent variables cannot.

h_f = figure; set(h_f,'Color', [0 0 0]);


function mystery_func(a)
b = a; h_a = gca; set(h_a,'Color', [0 0 0]);
return b; h_a = axes; set(h_a,'Color', [0 0 0]);
end
h_f = gcf; set(h_a,'Color', [0 0 0]);

Reference Q57. Which statement will return all the odd numbers from 1 to 9?

Q55. What is the state of a at the end of this code? 2*[1:5]+1

1:2:9

a = [1 2; 3 4]; isodd(1:9)
b = a(:,2);
1:odd:9
c = b + 3;
a(1:2,1) = c;
Q58. In MATLAB, the imfilter command performs a convolution operation between an
image and a matrix. Suppose you have an image loaded in MATLAB into the variable img
: and you apply the following code. The original image appears slightly blurred because the
convolution smoothed out the image (removed noise). Why do you think this happened?
a =
6 3 h = ones(5,5)/25;
7 4 imshow(imfilter(img,h));

: h is a Gaussian filter that adds to 1. Its intended effect is to highlight image edges.

h is an averaging filter uniformly distributed that adds to 1. Its intended effect is to


a = smooth out images (remove noise).
5 2
h is a Laplacian filter that adds up to 0. Its intended effect is to smooth out images
7 4
(remove noise).
imfilter is a function that always blurs the images.
:
Q59. What is the size of b ?
a =
5
a = [1 2 3];
7
b = repmat(a,2,3);

:
1x3
3x2
a =
6 2x3
7 2x9

Reference Q60. Which statement reverses vector a ?

Q56. You’ve just plotted some data and want to change the color behind the lines you’ve a = [ 1 2 3 4];
plotted to black. Which code block will accomplish this?
reverse(a) Reference
a(end:- 1:1)
Q66. Which is not a function to plot three-dimensional data?
rev(a)
a(::-1) mesh
surf
Q61. Which command will create a column vector with the values 7, 8, and 9?
contour
c = [7,8,9] grid
c = [7: 8: 9]
Reference
c = [7; 8; 9]

c = [7 8 9] Q67. What is the reason to save a MAT-file using the v-7.3 flag?

Q62. What do you call in the command window to see all the variables in the workspace and to use compression by default
their classes? to ensure backward compatibility

who
to include a variable greater than 2GB

vars
to avoid HDF5 overhead in MAT-file

whos Reference
who all
Q68. This graph could be the result of which block of code?
Q63. You wrote a new function named snap in an m-file and when you call it, you’re not
getting the output you expect. You previously wrote a different function named snap , which
you think might also be on the search path. Which command can you use to see if the old
snap function is being called?

which
who
lookfor
what

Q64. What is a reason to save a MAT-file using the -v7.3 flag?

to ensure backward compatibility


to avoid HDF5 overhead in MAT-file
to include a variable greater that 2GB
to use compression by default

Q65. Which choice cannot add a directory to the search path?

the path function


the savepath function
using Set Path in the Environment menu
the addpath function

a = randn(1,1000); histogram(a) ylabel('counts')


a = 1;
a = rand(1,1000); histogram(a) ylabel('counts') for i_loop = 1:6
a = randi(1,1000); histogram(a) ylabel('counts') disp(a);
end
a = rng(1,1000); histogram(a) ylabel('counts')

Q69. What is a key difference between && and &? :

&& is a logical operator and & is not.


111111
&& is always slower than &
&& employs short-circuiting behavior and & does not.
:
&& is a bitwise operator and & is not.

Reference 1 1 1 1 1 1

Q70. What is the result of this code? :

s="abcd"; s(3)='x' 1
1
1
“abxd”
1
abxd 1
1
a 1x 3 string array
a run-time error
:
Q71. In which case would you use varargin in a function you write?
nothing will print
You want to count the number of input arguments.
You want to include optional input arguments.
You want the workspace variable names of the input arguments. Q74. You are debugging a function and have set a breaipoint on the line before the error
occurs. You look at the variable values and suspect the cause of the error is that a is 9 but
You want the data types of the input arguments. should be 10. The next statement after the breakpoint will use a. Wigh action would help you
test if a=10 solves the problem?
Q72. What does e contain?
type “a=10;” into the function file, before the statement that’s throwing an error. Then click

c = [9 8 0];
the Run button in the debugger window.
d = [0 0 1]; Type “a=10; continue;” into the command window
e = union(c,d);
Type “a=10;” into the command window. Then click the Run button in the debugger
window
e = [0 0 1 9 8 0] Type “a=10;” into the function file, before the statement that’s throwing an error. Then
e = [9 8 0 0 0 1] type “return;” into the command window
e = [0 1 8 9]
Q75. Which statement returns the character array ‘alone’?
e = [1 8 9]

Q73. What does this function print?


else:
b = ['stand' 'alone']; b = 3;

:
b(7:11)
b(2)
if (a > 1){
b(6:end) b = 2;
b(1,2) } else{
b = 3;
}
Q76. Which statement returns the character array ‘alone’?

c = {rand(20,10) rand(23,2) rand(14,5)} :

if (a > 1)
:
b = 2;
else
b = cellfun(@(m) mean(m(:)), C b = 3;
end

:
:

b = zeros(1, size(C,1);
for i_C = 1:size(C,1) if (a > 1)
b(1_C) = mean(C{i_C}(:)); b = 2;
end else
b = 3;

:
Reference

b = cellfun(@mean, C)
Q78. What does b contain?

: a = [9 8 8 19 6 1 9 6 6 19];
b = unique(a);
b = zeros(1, size(C,2);
for i_C = 1:size(C,2)
b = [1 6 8 9 19]
b(1_C) = mean(C(i_C));
end b = [1 6 8 9]

b = [1 6 6 6 8 8 9 9 19 19]

b = [1 6 6 8 8 9]
Q77. Which choice uses the proper syntax for an if else statement?

:
This site is open source. Improve this page.
if (a > 1):
b = 2;

You might also like