These MATLAB multiple-choice questions and their answers will help you strengthen your grip on the subject of MATLAB. You can prepare for an upcoming exam or job interview with these 30 MATLAB MCQs.
So scroll down and start answering.

1: From what distribution does the rand() function return value?

A.   Normal

B.   Poisson

C.   Binomial

D.   Uniform

2: Based on the code below, c is the _ of a. a = rand(1, 11); b = sort(a); c = b(1, ceil(end/2));

A.   Median

B.   Mode

C.   Mean

D.   Margin

3: What does the Profiler track?

A.   Execution time

B.   Command history

C.   Errors

D.   The value of variables

4: What is %% used for?

A.   Argument placeholder

B.   Block quotes

C.   Code sections

D.   Conversion specifier

5: What is the . character NOT used for?

A.   Structure field access

B.   A decimal point

C.   Cell array access

D.   Element-wise operations

6: Which function could you use for multiple linear regression?

A.   Polyval

B.   Regress

C.   Solve

D.   Polyfit

7: For which of these arrays do mean, median, and mode return the same value?

A.   [0 1 1 1 2]

B.   [1 3 5 5 6]

C.   [0 1 1 1 1]

D.   [0 0 5 5 5]

8: 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)

A.   Your plot doesn't plot in a figure window because figure was not called immediately in advance.

B.   Your plot syntax is incorrect.

C.   Your plot is in a figure window that was already open, hidden behind other windows on your screen.

D.   Your plot was saved to an image file but not displayed.

9: How do you access the value for the field name in structure S?

A.   S['name']


C.   S('name')

D.   S{'name'}

10: What built-in definition does i have?

A.   Basic imaginary unit

B.   Index function

C.   Infinity

D.   Index variable

11: 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?

A.   Xticks(-3pi:3.14:3pi)

B.   Xticks(-3pi:pi:3pi)

C.   Xticks(linespace(-3pi(), 3pi(), pi()))

D.   Xticks(linespace(-3pi, 3pi, pi)

12: Which function CANNOT be used to randomly sample data?

A.   Datasample

B.   Randi

C.   Resample

D.   Randperm

13: What is true of a handle class object?

A.   When you pass a handle object to a function, a new object is made that is independent of the original.

B.   All copies of handle objects refer to the same underlying object.

C.   Handle object cannot reference one another.

D.   Handle object do not have a default eq function.

14: Which statement could create this cell array? c = {["hello world"]} {1×1 cell} {["goodbye"]} {1×3 double}

A.   c = {"hello world" {"hello"} "goodbye" [1 2 ]};

B.   c = {"hello world" {"hello"} "goodbye" {[1 2 3]}};

C.   c = {"hello world" {"hello"} "goodbye" [1 2 3]};

D.   c = {"hello world" {"hello" "hello"} "goodbye" {[1 2 3]}};

15: Which choice adds b to each row of a? a = ones(4, 4); b= [1 2 3 4];

A.   A = a + reshape(b, 4, 1);

B.   A = a + b';

C.   A = a + repmat(b, 4, 1);

D.   A = a + [b b b b];

16: Which statement returns the roots for the polynomial x^2 + 2x - 4?

A.   Poly([1 2 -4])

B.   Solve(x^2 + 2x - 4 == 0)

C.   Polyfit(x^2 + 2x - 4 == 0)

D.   Roots([1 2 -4])

17: Which choice is the proper syntax to append a new elements a to the end of 1x 2 dimensional cell array C?

A.   C = {C a};

B.   C = cellcat(C a)

C.   C = cat(2, {a}, C)

D.   C{end+1}=a

18: 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?

A.   Sim_height = std(height) + mean(height) * randn(100, 1);

B.   Sim_height = mean(height) + std(height) * randn(100, 1);

C.   Sim_height = randn(std(height), mean(height), [100, 1]);

D.   Sim_height = randn(mean(height), std(height), [100, 1]);

19: Which statement returns a cell array of the strings containing 'burger' from menu? Menu = {'hot dog' 'corn dog' 'regular burger' 'cheeseburger' 'veggie burger'}

A.   Menu{strfind(menu, 'burger')}

B.   Menu(strfind(menu, 'burger'))

C.   Menu{contains(menu, 'burger')}

D.   Menu(contains(menu, 'burger'))

20: Which statement is true about the sparse matrices?

A.   You can use the sparse function to remove empty cells from cell array variables.

B.   Sparse matrices always use less memory than their associated full matrices.

C.   Mixtures of sparse and full matrices can be combined in all of MATLAB's built-in arithmetic operations.

D.   The sparse function requires its input to be a full matrix with at least 50% zero elements.

21: Which statement using logical indices will result in an error? A = 1:10;

A.   B = a(a ~= 11)

B.   B = a(a == 1)

C.   B = a(a>6 && a<9)

D.   B = a(a | 1)

22: 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'};

A.   Contains(password, '\d')

B.   ~isempty(regexp(passwords, '\d'))

C.   Cellfun(@(x) ~isempty(regexp(x, '\d')), passwords)

D.   Regexp(passwords, '\d')

23: Which is NOT a function that adds text to a plot?

A.   Title

B.   Text

C.   Label

D.   Legend

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

A.   Figure files

B.   Script files

C.   Function files

D.   Stored variable files

25: Which statement returns 1 (true)? a = 'stand' b = "stand"

A.   a == b

B.   Ischar(b)

C.   Length(a) == length(b)

D.   Class(a) == class(b)

26: Where in the UI can you see what variables have been created, their values, and their class?

A.   Editor

B.   Command window

C.   Details

D.   Workspace

27: If you run this piece of code, you will get an error. Why? a = [0 1 2 3; 4 5 6 7]; a = a^2;

A.   You are attempting to multiply a non-square matrix by itself, causing a dimension mismatch.

B.   MATLAB does not allow you to square all the elements in the matrix in a single operation.

C.   You must use the ** operator instead of the ^ operator.

D.   You cannot square matrices that have a 0 as the first element.

28: Which command will create a 10-element vector v with values from 1 to 10?

A.   V = {1:10}

B.   V = [1-10]

C.   V = 1:10

D.   V = (10)

29: For a 5 x 5 array, the two subscript index (4,2) indexes the same location as linear index ___.

A.   7

B.   8

C.   17

D.   9

30: What is a difference between global variable and persistent variables?

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

B.   Global variables remain in memory after clear all; persistent variables do not.

C.   Global variables can be used to cache data in memory; persistent variables cannot.

D.   Global variables are accessible outside the function scope; persistent variables are not.

31: How is the random seed for MATLAB's random number generator first initializedin a MATLAB Session?

A.   Seed is undefined until it is initialized by the user.

B.   Seed is set to a value based on the current time when user first calls rand()

C.   Seed is set to a value based on the current time on startup.

D.   Seed is set to a static default value on startup.

32: You've just plotted some data and want to change the color behind the lines you've plotted to black. Which code block will accomplish this?

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

B.   h_a = gca; set(h_a,'Color', [0 0 0]);

C.   h_a = axes; set(h_a,'Color', [0 0 0]);

D.   h_f = gcf; set(h_a,'Color', [0 0 0]);

33: Which statement will return all the odd numbers from 1 to 9?

A.   2*[1:5]+1

B.   1:2:9

C.   Isodd(1:9)

D.   1:odd:9

34: What is the size of b? a = [1 2 3]; b = repmat(a,2,3);

A.   1x3

B.   3x2

C.   2x3

D.   2x9

35: Which statement reverses vector a? A = [ 1 2 3 4];

A.   Reverse(a)

B.   A(end:- 1:1)

C.   Rev(a)

D.   A(::-1)

36: Which command will create a column vector with the values 7, 8, and 9?

A.   C = [7,8,9]

B.   C = [7: 8: 9]

C.   C = [7; 8; 9]

D.   C = [7 8 9]

37: What do you call in the command window to see all the variables in the workspace and their classes?

A.   Who

B.   Vars

C.   Whos

D.   Who all

38: 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?

A.   Which

B.   Who

C.   Lookfor

D.   What

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

A.   To ensure backward compatibility

B.   To avoid HDF5 overhead in MAT-file

C.   To include a variable greater that 2GB

D.   To use compression by default