Categories: Arrays, Matrices, Plotting, Logic, Functions
Matrices
Plotting
Logic
Functions
100

How do you create an array of 10 evenly spaced numbers between 0 and 5?

linspace(0, 5, 10)

100

What function creates a 4x4 identity matrix?

eye(4)

100

Which function adds a title to a MATLAB plot?

title

100

What does num > 10 return if num = 15?

true

100

What keyword is used to define a function in MATLAB?

function

200

What is the output of this code: x = 1:2:9; disp(x);?

[1, 3, 5, 7, 9]

200

How do you access the element in the 2nd row, 3rd column of matrix A?

A(2, 3)

200

What MATLAB command overlays multiple plots on the same figure?

hold on

200

Write a simple if statement that displays "Yes" if x > 5.

200

How do you specify multiple outputs in a MATLAB function?

Use square brackets: [out1, out2] = myFunction(inputs)

300

Which MATLAB function returns the indices of non-zero elements in an array?

find

300

If A = [1, 2; 3, 4] and B = [5, 6; 7, 8], what is A .* B?

[5, 12; 21, 32]

300

How do you label the y-axis of a plot with the text "Amplitude"?

ylabel('Amplitude')

300

What is the difference between && and & in MATLAB?

&& is used for short-circuit logical operations; & is for element-wise logical operations.

300

What does this function return for x = 2?

16

400

If A = [1, 2, 3]; B = [4, 5, 6];, what does C = [A; B]; create?

A 2x3 matrix 

[1, 2, 3;

 4, 5, 6]


400

What is the determinant of the matrix A = [1, 2; 3, 4]?

det(A) = -2

400

What command would you use to create a subplot with 2 rows and 3 columns in the first position?

subplot(2, 3, 1)

400

 If x = 0, what does this code display?


Zero

400

Write a function that computes the area of a circle given the radius.

500

Write a command to extract every 3rd element from an array x.

x(1:3:end)

500

What does rank([1, 2; 2, 4]) return, and why?

1 because the rows are linearly dependent.

500

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);

500

What will this code output?

Empty array

500

What does nargin do inside a MATLAB function?

 Returns the number of input arguments passed to the function.