How do you create an array of 10 evenly spaced numbers between 0 and 5?
linspace(0, 5, 10)
What function creates a 4x4 identity matrix?
eye(4)
Which function adds a title to a MATLAB plot?
title
What does num > 10 return if num = 15?
true
What keyword is used to define a function in MATLAB?
function
What is the output of this code: x = 1:2:9; disp(x);?
[1, 3, 5, 7, 9]
How do you access the element in the 2nd row, 3rd column of matrix A?
A(2, 3)
What MATLAB command overlays multiple plots on the same figure?
hold on
Write a simple if statement that displays "Yes" if x > 5.
How do you specify multiple outputs in a MATLAB function?
Use square brackets: [out1, out2] = myFunction(inputs)
Which MATLAB function returns the indices of non-zero elements in an array?
find
If A = [1, 2; 3, 4] and B = [5, 6; 7, 8], what is A .* B?
[5, 12; 21, 32]
How do you label the y-axis of a plot with the text "Amplitude"?
ylabel('Amplitude')
What is the difference between && and & in MATLAB?
&& is used for short-circuit logical operations; & is for element-wise logical operations.
What does this function return for x = 2?
16
If A = [1, 2, 3]; B = [4, 5, 6];, what does C = [A; B]; create?
A 2x3 matrix
[1, 2, 3;
4, 5, 6]
What is the determinant of the matrix A = [1, 2; 3, 4]?
det(A) = -2
What command would you use to create a subplot with 2 rows and 3 columns in the first position?
subplot(2, 3, 1)
If x = 0, what does this code display?
Zero
Write a function that computes the area of a circle given the radius.
Write a command to extract every 3rd element from an array x.
x(1:3:end)
What does rank([1, 2; 2, 4]) return, and why?
1 because the rows are linearly dependent.
Write the command to plot y=x2y = x^2y=x2 for x=−5x = -5x=−5 to x=5x = 5x=5.
x = -5:0.1:5; y = x.^2; plot(x, y);
What will this code output?
Empty array
What does nargin do inside a MATLAB function?
Returns the number of input arguments passed to the function.