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

MATLAB_Questions

The document contains a series of MATLAB-related questions and answers, covering various topics such as commands, functions, and programming concepts. Key topics include matrix operations, plotting, logical operations, and script execution. Each question is followed by the correct answer, providing a comprehensive overview of MATLAB functionalities.

Uploaded by

siddana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

MATLAB_Questions

The document contains a series of MATLAB-related questions and answers, covering various topics such as commands, functions, and programming concepts. Key topics include matrix operations, plotting, logical operations, and script execution. Each question is followed by the correct answer, providing a comprehensive overview of MATLAB functionalities.

Uploaded by

siddana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

MATLAB Questions

1. MATLAB stands for:


a) Matrix Laboratory
b) Math Laboratory
c) Matrix Libraries
d) Matrix Lab
Answer: a) Matrix Laboratory

2. What is the file extension for MATLAB scripts?


a) .mat
b) .m
c) .mlab
d) .txt
Answer: b) .m

3. Which command is used to clear variables in the workspace?


a) clc
b) clear
c) reset
d) del
Answer: b) clear

4. How does MATLAB index arrays?


a) From 0
b) From 1
c) Dynamically
d) None of the above
Answer: b) From 1

5. Which operator is used for element-wise multiplication in MATLAB?


a) *
b) .*
c) **
d) ./
Answer: b) .*

6. How to create a 4x4 identity matrix in MATLAB?


a) iden(4)
b) eye(4)
c) ones(4)
d) diag(4)
Answer: b) eye(4)
7. Which function is used to find the size of a matrix?
a) size()
b) dim()
c) shape()
d) matrix_size()
Answer: a) size()

8. What does the zeros(3) command do?


a) Creates a 3x3 matrix of ones
b) Creates a 3x3 matrix of zeros
c) Generates a 3-element vector of zeros
d) Produces an error
Answer: b) Creates a 3x3 matrix of zeros

9. How to transpose a matrix A?


a) transpose(A)
b) A'
c) T(A)
d) flip(A)
Answer: b) A'

10. Which function calculates the determinant of a matrix?


a) det()
b) determinant()
c) calculate_det()
d) find_det()
Answer: a) det()

11. Plotting

12. What does the plot function do in MATLAB?


a) Plots graphs
b) Draws tables
c) Displays text
d) Generates images
Answer: a) Plots graphs

13. Which command creates a 3D surface plot?


a) surface()
b) surf()
c) plot3()
d) meshgrid()
Answer: b) surf()
14. What is the purpose of the legend function?
a) Add gridlines
b) Label axes
c) Add labels to plots
d) Create a colorbar
Answer: c) Add labels to plots

15. What does the hold on command do?


a) Clears the current figure
b) Overlays multiple plots
c) Pauses script execution
d) Resets the plot area
Answer: b) Overlays multiple plots

16. Which function is used to label the x-axis of a plot?


a) x_label()
b) xlabel()
c) axis_label()
d) label_x()
Answer: b) xlabel()

18. What is the output of 1:2:10?


a) [1 3 5 7 9]
b) [1 2 3 4 5]
c) [1 4 7 10]
d) [1 2 10]
Answer: a) [1 3 5 7 9]

19. Which loop is used to iterate over a specific range of values?


a) while
b) do
c) for
d) repeat
Answer: c) for

20. What does the if statement do in MATLAB?


a) Repeats code
b) Executes code conditionally
c) Displays output
d) Imports data
Answer: b) Executes code conditionally
21. How do you terminate a script execution in MATLAB?
a) break
b) end
c) stop
d) return
Answer: d) return

22. Which keyword defines a function in MATLAB?


a) def
b) function
c) func
d) define
Answer: b) function

23. What does the load command do?


a) Imports MATLAB files
b) Displays data
c) Exports files
d) Deletes variables
Answer: a) Imports MATLAB files

24. Which function saves workspace variables to a file?


a) save()
b) store()
c) dump()
d) backup()
Answer: a) save()

25. What is the result of sum([1,2,3,4])?


a) 10
b) [10]
c) [1 2 3 4]
d) Error
Answer: a) 10

26. How to find the mean of an array A?


a) mean(A)
b) average(A)
c) avg(A)
d) mean_array(A)
Answer: a) mean(A)
27. Which command removes rows with missing data?
a) clean_rows()
b) rmmissing()
c) del_rows()
d) fill_missing()
Answer: b) rmmissing()

29. What is Simulink used for in MATLAB?


a) Statistical modeling
b) 3D plotting
c) Simulation and modeling
d) Animation
Answer: c) Simulation and modeling

30. What does fft compute in MATLAB?


a) Fast Fourier Transform
b) Frequency Transform
c) Functional Transform
d) Filter Function Transform
Answer: a) Fast Fourier Transform

31. Which command generates random numbers in MATLAB?


a) random()
b) rand()
c) rnd()
d) randint()
Answer: b) rand()

32. What is the output of length([1 2; 3 4])?


a) 2
b) 4
c) 3
d) Error
Answer: a) 2

33. Which command finds the eigenvalues of a matrix?


a) eigen()
b) eig()
c) eigvals()
d) find_eigen()
Answer: b) eig()
35. How do you terminate a line of code in MATLAB?
a) Semicolon (;)
b) Comma (,)
c) Colon (:)
d) No termination needed
Answer: a) Semicolon (;)

36. Which function creates linearly spaced vectors?


a) linspace()
b) space()
c) range()
d) grid()
Answer: a) linspace()

37. What is the shortcut to run a script in MATLAB?


a) F4
b) F5
c) Ctrl+R
d) Alt+R
Answer: b) F5

38. Which workspace variable lists the current variables?


a) who
b) whos
c) ls
d) list
Answer: b) whos

39. Which command stops an infinite loop in MATLAB?


a) exit
b) stop
c) Ctrl+C
d) End
Answer: c) Ctrl+C

41. What does mod(10,3) return?


a) 1
b) 2
c) 3
d) 10
Answer: a) 1
42. Which operator is used for logical AND in MATLAB?
a) &&
b) ||
c) &
d) !
Answer: a) &&

43. How to convert a number to a string in MATLAB?


a) num2str()
b) str()
c) tostring()
d) convert()
Answer: a) num2str()

44. Which command calculates the natural logarithm of a value?


a) ln()
b) log()
c) exp()
d) log10()
Answer: b) log()

45. What does diag(A) do?


a) Creates a diagonal matrix from A
b) Finds the determinant of A
c) Extracts the diagonal elements of A
d) Calculates the trace of A
Answer: c) Extracts the diagonal elements of A

47. Which command is used to find the maximum value in an array?


a) maxval()
b) max()
c) maximum()
d) findmax()
Answer: b) max()

48. How can you generate a vector of random integers between 1 and 10?
a) randint(1,10)
b) rand(1,10)
c) randi([1,10])
d) randint(10)
Answer: c) randi([1,10])
49. What does the command diag([1, 2, 3]) return?
a) [1 2 3]
b) A 3x3 diagonal matrix
c) A 2x2 diagonal matrix
d) Error
Answer: b) A 3x3 diagonal matrix

50. Which function is used to calculate the cross product of two vectors?
a) dot()
b) cross()
c) mult()
d) vectorprod()
Answer: b) cross()

51. What is the default value for the step in start:step:end if step is not provided?
a) 0
b) 1
c) -1
d) Undefined
Answer: b) 1

53. How do you compute the inverse of a square matrix A in MATLAB?


a) inverse(A)
b) A^-1
c) inv(A)
d) rev(A)
Answer: c) inv(A)

54. What does the function reshape(A, [3,2]) do?


a) Changes A into a 3x2 matrix
b) Changes A into a 2x3 matrix
c) Rotates A
d) Creates a diagonal matrix from A
Answer: a) Changes A into a 3x2 matrix

55. What does the command rank(A) return?


a) Number of nonzero elements in A
b) Rank of matrix A
c) Eigenvalues of A
d) Trace of A
Answer: b) Rank of matrix A
56. Which command converts a matrix to a column vector in MATLAB?
a) vectorize(A)
b) col(A)
c) reshape(A,[],1)
d) columnize(A)
Answer: c) reshape(A,[],1)

57. How do you compute the Frobenius norm of a matrix A?


a) frob(A)
b) norm(A,'fro')
c) norm(A)
d) abs(A)
Answer: b) norm(A,'fro')

59. What is the output of the command strcmp('MATLAB', 'matlab')?


a) true
b) false
c) 1
d) Error
Answer: b) false

60. Which MATLAB function is used to measure execution time?


a) time()
b) timer()
c) tic and toc
d) measure()
Answer: c) tic and toc

61. What is the difference between break and continue in a loop?


a) break stops the loop, continue skips to the next iteration
b) Both stop the loop
c) break repeats the loop, continue stops it
d) No difference
Answer: a) break stops the loop, continue skips to the next iteration

62. Which command checks if a variable exists in the workspace?


a) check()
b) exist()
c) validate()
d) isvar()
Answer: b) exist()
63. What is the purpose of the switch-case statement in MATLAB?
a) To handle conditional loops
b) To define multiple cases for a variable
c) To switch between scripts
d) To stop execution
Answer: b) To define multiple cases for a variable

65. How do you create a bar graph in MATLAB?


a) bar()
b) barplot()
c) graph_bar()
d) hist_bar()
Answer: a) bar()

66. Which command overlays a grid on a plot?


a) gridon()
b) grid()
c) gridlines()
d) addgrid()
Answer: b) grid()

67. What does the subplot(2,2,3) command do?


a) Creates a 2x2 grid of plots and selects the 3rd subplot
b) Divides the current plot into two subplots
c) Creates three plots vertically
d) Displays three plots in a single figure
Answer: a) Creates a 2x2 grid of plots and selects the 3rd subplot

68. Which command is used to export a figure as an image file?


a) save()
b) export_fig()
c) saveas()
d) image()
Answer: c) saveas()

69. Which function adjusts the aspect ratio of a plot?


a) adjust_aspect()
b) axis()
c) aspect()
d) ratio()
Answer: b) axis()
71. What does polyfit(x, y, 2) compute?
a) A polynomial of degree 2 fitting the data (x, y)
b) A line fitting the data
c) Roots of a quadratic equation
d) Eigenvalues of the matrix
Answer: a) A polynomial of degree 2 fitting the data

72. How do you solve a system of linear equations Ax = b in MATLAB?


a) x = solve(A, b)
b) x = A\b
c) x = inv(A)*b
d) x = linsolve(A, b)
Answer: b) x = A\b

73. What does the fftshift function do?


a) Shifts the zero frequency to the center
b) Computes the FFT
c) Applies a filter
d) Normalizes the signal
Answer: a) Shifts the zero frequency to the center

74. What is the purpose of meshgrid in MATLAB?


a) To create 2D and 3D grids for plotting
b) To plot 3D surfaces
c) To interpolate data
d) To create line plots
Answer: a) To create 2D and 3D grids for plotting

75. Which function creates logarithmically spaced vectors?


a) logspace()
b) loggrid()
c) linlog()
d) log_vector()
Answer: a) logspace()

77. Which command provides help for a specific MATLAB function?


a) info()
b) help()
c) support()
d) doc()
Answer: b) help()
78. How can you measure the size of a vector v?
a) dim(v)
b) length(v)
c) size(v)
d) count(v)
Answer: b) length(v)

79. What is the result of fix(3.7)?


a) 3
b) 4
c) 3.7
d) -3
Answer: a) 3

80. What is the purpose of the disp command?


a) Display variables in the workspace
b) Display text or variable values
c) Delete variables
d) Save variables
Answer: b) Display text or variable values

81. Which command is used to pause execution for a specific amount of time?
a) pause()
b) wait()
c) halt()
d) sleep()
Answer: a) pause()

83. What does sum(A,2) compute?


a) Sum of each row in matrix A
b) Sum of each column in matrix A
c) Sum of all elements in A
d) Cumulative sum along rows of A
Answer: a) Sum of each row in matrix A

84. What is the result of diag(eye(3))?


a) A 3x3 identity matrix
b) A column vector [1 1 1]
c) A 3x3 zero matrix
d) Error
Answer: b) A column vector [1 1 1]
85. How do you access the third row of matrix A?
a) A(:,3)
b) A(3,:)
c) A(3,3)
d) A(3)
Answer: b) A(3,:)

86. What is the result of magic(3)?


a) A 3x3 identity matrix
b) A 3x3 diagonal matrix
c) A 3x3 magic square
d) A 3x3 random matrix
Answer: c) A 3x3 magic square

87. Which function flattens a matrix into a single row?


a) flatten(A)
b) reshape(A,1,[])
c) vectorize(A)
d) col(A)
Answer: b) reshape(A,1,[])

88. MATLAB Logical Operations

89. What does isempty(A) return?


a) True if A is empty
b) The size of A
c) True if A contains only zeros
d) False if A contains any element
Answer: a) True if A is empty

90. How do you check if two arrays are equal?


a) A == B
b) isequal(A,B)
c) compare(A,B)
d) check(A,B)
Answer: b) isequal(A,B)

91. Which operator represents logical OR in MATLAB?


a) &
b) ||
c) |
d) !
Answer: c) |
92. What is the result of all([1, 1, 0])?
a) 0
b) 1
c) Error
d) False
Answer: a) 0

93. How can you find the indices of non-zero elements in a matrix?
a) nonzero(A)
b) find(A)
c) index(A)
d) locate(A)

95. What does polyval(p, x) compute?


a) Roots of a polynomial p
b) Derivative of a polynomial p
c) Value of the polynomial p at x
d) Coefficients of a polynomial
Answer: c) Value of the polynomial p at x

96. How do you generate linearly spaced values between 0 and 1?


a) linspace(0,1,n)
b) linspace(1,0)
c) range(0,1)
d) generate(0,1)
Answer: a) linspace(0,1,n)

97. What does gradient(f) compute?


a) The integral of f
b) The derivative of f
c) The numerical gradient of f
d) The second derivative of f
Answer: c) The numerical gradient of f

99. What is the output of randperm(5)?


a) A vector of 5 random numbers
b) A permutation of numbers 1 to 5
c) A vector of random integers between 1 and 5
d) A 5x5 random matrix
Answer: b) A permutation of numbers 1 to 5
102. Which command visualizes data density in MATLAB?
a) histogram()
b) heatmap()
c) density()
d) surf()
Answer: b) heatmap()

107. What does log10(100) return?


a) 1
b) 2
c) 10
d) 100
Answer: b) 2

109. How do you add a title to a MATLAB plot?


a) plot_title()
b) title()
c) addtitle()
d) name()
Answer: b) title()

You might also like