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

Top 47 MATLAB MCQs With Answers

This document provides 47 multiple choice questions to test knowledge of MATLAB. It covers basic MATLAB concepts like what MATLAB stands for, how to create variables and loops, and commands for matrices, plotting, random number generation, and more. Each question is followed by an answer and brief explanation of the concept or code being tested.

Uploaded by

Renzo Ferrer
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
363 views

Top 47 MATLAB MCQs With Answers

This document provides 47 multiple choice questions to test knowledge of MATLAB. It covers basic MATLAB concepts like what MATLAB stands for, how to create variables and loops, and commands for matrices, plotting, random number generation, and more. Each question is followed by an answer and brief explanation of the concept or code being tested.

Uploaded by

Renzo Ferrer
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Top 47 MATLAB MCQs with Answers | MATLAB Quiz

1. What does MATLAB stand for?

A) Math Analysis Language Tool


B) Matrix Analysis Language Tool
C) Mathematical Analysis Language
D) Matrix Laboratory

Answer: D) Matrix Laboratory.

Explanation: MATLAB stands for Matrix Laboratory, and it is a programming language


developed by MathWorks for technical computing.

2. Which command in MATLAB is used to create a new variable?

A) new
B) var
C) create
D) let

Answer: B) var.

3. What is the default extension of a MATLAB script file?

A) .mat
B) .m
C) .md
D) .txt
Answer: B) .m.

4. Which of the following statements is used to create a for loop in MATLAB?

A) while
B) do-while
C) for
D) repeat-until

Answer: C) for.

5. Which command in MATLAB is used to display the contents of a variable?

A) show
B) display
C) disp
D) print

Answer: C) disp.

6. What is the result of the following expression in MATLAB: 3 + 5 * 2

A) 16
B) 13
C) 11
D) 15

Answer: D) 13.
Explanation: The expression is evaluated using the order of operations, so the
multiplication is done first, followed by the addition. Thus, the result is 3 + 10 = 15.

7. Which of the following commands is used to create a matrix with all elements
set to 0?

A) zeros
B) ones
C) eye
D) rand

Answer: A) zeros.

8. Which of the following commands is used to calculate the square root of a


number in MATLAB?

A) sqrt
B) root
C) power
D) exp

Answer: A) sqrt.

9. Which of the following commands is used to generate a random number in


MATLAB?

A) random
B) rand
C) randn
D) randomize
Answer: B) ranD)

10. Which of the following commands is used to read input from the user in
MATLAB?

A) input
B) read
C) readln
D) get

Answer: A) input.

11. What is the result of the following code in MATLAB:

a = [1 2 3; 4 5 6];
b = [7 8 9; 10 11 12];
c = a + b;

A) [8 10 12; 14 16 18]
B) [7 8 9 10 11 12]
C) [7 10 12; 14 16 18]
D) [8 11 14; 17 20 23]

Answer: D) [8 11 14; 17 20 23].

Explanation: The code creates two matrices, ‘a’ and ‘b’, and then adds them together
using the ‘+’ operator. The resulting matrix ‘c’ is:

1+7 2+7 3+9


4+10 5+11 6+12
which simplifies to:
[8 11 14;
17 20 23]

12. Which command in MATLAB is used to create a plot?

A) plot
B) createplot
C) drawplot
D) makeplot

Answer: A) plot.

13. Which of the following commands is used to find the maximum element of a
matrix in MATLAB?

A) min
B) max
C) maximum
D) findmax

Answer: B) max.

14. Which of the following commands is used to concatenate two matrices


vertically in MATLAB?

A) horzcat
B) vertcat
C) cat
D) merge
Answer: B) vertcat.

15. Which of the following commands is used to calculate the dot product of two
vectors in MATLAB?

A) dot
B) cross
C) inner
D) product

Answer: A) dot.

16. What is the result of the following code in MATLAB:

x = 1:5;
y = x.^2;

A) x = [1 2 3 4 5], y = [1 4 9 16 25]
B) x = [1 2 3 4 5], y = [2 4 6 8 10]
C) x = [1 2 3 4 5], y = [1 2 3 4 5]
D) x = [1 2 3 4 5], y = [1 3 5 7 9]

Answer: A) x = [1 2 3 4 5], y = [1 4 9 16 25].

Explanation: The code creates a vector ‘x’ with values 1 through 5, and then creates a
new vector ‘y’ by squaring each element of ‘x’. The resulting vector ‘y’ is [1 4 9 16 25].

17. Which of the following commands is used to convert a string to uppercase in


MATLAB?
A) upper
B) toUpperCase
C) toUpper
D) uppercase

Answer: A) upper.

18. Which of the following commands is used to round a number to the nearest
integer in MATLAB?

A) round
B) ceil
C) floor
D) fix

Answer: A) rounD)

19. Which of the following commands is used to find the indices of the non-zero
elements in a matrix in MATLAB?

A) nonzero
B) find
C) index
D) locate

Answer: B) finD)

20. What is the result of the following code in MATLAB:


x = 0:pi/10:2*pi;
y = sin(x);

A) x is a vector with 11 elements, y is a vector with 11 elements


B) x is a vector with 21 elements, y is a vector with 21 elements
C) x is a vector with 11 elements, y is a vector with 21 elements
D) x is a vector with 21 elements, y is a vector with 11 elements

Answer: B) x is a vector with 21 elements, y is a vector with 21 elements.

Explanation: The code creates a vector ‘x’ with values ranging from 0 to 2*pi in
increments of pi/10, and then creates a new vector ‘y’ by taking the sine of each
element of ‘x’. The resulting vectors ‘x’ and ‘y’ both have 21 elements.

21. Which of the following commands is used to generate a random number


between 0 and 1 in MATLAB?

A) random
B) rand
C) randomize
D) randn

Answer: B) ranD)

22. Which of the following commands is used to calculate the inverse of a matrix
in MATLAB?

A) inverse
B) inv
C) transpose
D) invert

Answer: B) inv.

23. Which of the following commands is used to calculate the square root of a
number in MATLAB?

A) sqrt
B) square
C) squareroot
D) root

Answer: A) sqrt.

24. Which of the following commands is used to calculate the transpose of a


matrix in MATLAB?

A) transpose
B) trans
C) t
D) tr

Answer: C) t.

25. What is the result of the following code in MATLAB:

x = [1 2; 3 4];
y = [5 6; 7 8];
z = x*y;
A) z = [7 10; 15 22]
B) z = [19 22; 43 50]
C) z = [11 14; 23 26]
D) z = [12 15; 18 21]

Answer: B) z = [19 22; 43 50].

Explanation: The code creates two 2×2 matrices ‘x’ and ‘y’, and then multiplies them
using the * operator to create a new matrix ‘z’. The resulting matrix ‘z’ is [19 22; 43 50].

26. Which of the following commands is used to calculate the determinant of a


matrix in MATLAB?

A) det
B) determinant
C) detmat
D) matdet

Answer: A) det.

27. Which of the following commands is used to calculate the mean of a matrix in
MATLAB?

A) mean
B) avg
C) average
D) matmean

Answer: A) mean.
28. Which of the following commands is used to calculate the standard deviation
of a matrix in MATLAB?

A) stddev
B) stdev
C) std
D) deviation

Answer: C) stD)

29. Which of the following commands is used to create a diagonal matrix in


MATLAB?

A) diag
B) diagonal
C) diags
D) matdiag

Answer: A) diag.

30. What is the result of the following code in MATLAB:

x = [1 2 3];
y = [4 5 6];
z = [7 8 9];
a = [x; y; z];

A) a = [1 2 3; 4 5 6; 7 8 9]
B) a = [1 4 7; 2 5 8; 3 6 9]
C) a = [1 2 3 4 5 6 7 8 9]
D) a = [1 2 3; 4 5 6; 7 8 9;]

Answer: B) a = [1 4 7; 2 5 8; 3 6 9].

Explanation: The code creates three 1×3 row vectors ‘x’, ‘y’, and ‘z’, and then
combines them into a 3×3 matrix ‘a’ using the semicolon (;) operator. The resulting
matrix ‘a’ is [1 4 7; 2 5 8; 3 6 9].

31. Which of the following commands is used to find the maximum value in a
matrix in MATLAB?

A) maxval
B) max
C) maximum
D) matmax

Answer: B) max.

32. Which of the following commands is used to find the minimum value in a
matrix in MATLAB?

A) minval
B) min
C) minimum
D) matmin

Answer: B) min.
33. Which of the following commands is used to calculate the dot product of two
vectors in MATLAB?

A) dot
B) product
C) dotprod
D) vecdot

Answer: A) dot.

34. Which of the following commands is used to calculate the cross product of
two vectors in MATLAB?

A) crossprod
B) cross
C) veccross
D) xprod

Answer: B) cross.

35. Which of the following commands is used to calculate the norm of a vector in
MATLAB?

A) norm
B) vecnorm
C) vectornorm
D) normvec

Answer: A) norm.
36. Which of the following commands is used to calculate the eigenvalues of a
matrix in MATLAB?

A) eig
B) eigen
C) eigm
D) mat_eig

Answer: A) eig.

37. Which of the following commands is used to create a sparse matrix in


MATLAB?

A) spr
B) sparse
C) sparsify
D) sp_matrix

Answer: B) sparse.

38. Which of the following commands is used to resize an array in MATLAB?

A) size
B) reshape
C) resize
D) arrayresize

Answer: B) reshape.
39. Which of the following commands is used to concatenate two matrices
horizontally in MATLAB?

A) horzcat
B) cat
C) concat
D) hcat

Answer: A) horzcat.

40. Which of the following commands is used to concatenate two matrices


vertically in MATLAB?

A) vertcat
B) cat
C) concat
D) vcat

Answer: A) vertcat.

41. Which of the following commands is used to generate a random number


between 0 and 1 in MATLAB?

A) rand
B) randn
C) randi
D) random

Answer: A) ranD)
42. Which of the following commands is used to generate a random integer
between two specified values in MATLAB?

A) rand
B) randn
C) randi
D) random

Answer: C) randi.

43. Which of the following commands is used to generate an array of normally


distributed random numbers in MATLAB?

A) rand
B) randn
C) randi
D) random

Answer: B) randn.

44. Which of the following commands is used to round a number up to the


nearest integer in MATLAB?

A) ceil
B) floor
C) round
D) int

Answer: A) ceil.
45. Which of the following commands is used to round a number down to the
nearest integer in MATLAB?

A) ceil
B) floor
C) round
D) int

Answer: B) floor.

46. Which of the following commands is used to create a plot in MATLAB?

A) plot
B) createplot
C) plotgraph
D) drawplot

Answer: A) plot.

47. Which of the following commands is used to create a scatter plot in MATLAB?

A) plot
B) scatter
C) scatterplot
D) plotscatter

Answer: B) scatter.

You might also like