MCQ Related “MATLAB”

  1. What is the default data type for a variable in MATLAB?
    • A) Integer
    • B) String
    • C) Double
    • D) Char
  2. Which command is used to clear all variables from the workspace?
    • A) clear all
    • B) clearvars
    • C) remove all
    • D) deletevars
  3. How do you create a 3×3 identity matrix in MATLAB?
    • A) eye(3)
    • B) id(3)
    • C) matrix(3)
    • D) ones(3)
  4. Which function is used to find the size of a matrix?
    • A) length()
    • B) size()
    • C) dimensions()
    • D) matrix_size()
  5. What operator is used for matrix multiplication?
    • A) *
    • B) .
    • C) x
    • D) @
  6. How would you create a row vector with values from 1 to 10?
    • A) [1:10]
    • B) (1:10)
    • C) {1:10}
    • D) [1; 10]
  7. What is the command for generating random numbers in a specified range?
    • A) rand(min, max)
    • B) random(min, max)
    • C) randi(min, max)
    • D) randrange(min, max)
  8. Which command displays a message in the command window?
    • A) show()
    • B) display()
    • C) fprintf()
    • D) msg()
  9. What is the primary file extension for MATLAB scripts?
    • A) .mat
    • B) .ml
    • C) .m
    • D) .txt
  10. Which function is used to plot a graph in MATLAB?
    • A) plot()
    • B) graph()
    • C) chart()
    • D) draw()
  11. In MATLAB, how do you access the third element of a vector named vec?
    • A) vec[3]
    • B) vec(3)
    • C) vec{3}
    • D) vec.3
  12. What is the command to save the current workspace variables to a file?
    • A) savefile()
    • B) save()
    • C) export()
    • D) store()
  13. Which function is used to read data from a text file?
    • A) readfile()
    • B) load()
    • C) importdata()
    • D) readdata()
  14. How do you comment a single line in MATLAB?
    • A) //
    • B) #
    • C) %%
    • D) —
  15. What function generates normally distributed random numbers?
    • A) randn()
    • B) randomn()
    • C) normrand()
    • D) gaussian()
  16. Which command is used to find the maximum value in an array?
    • A) maxvalue()
    • B) maximum()
    • C) max()
    • D) highest()
  17. How can you concatenate two matrices A and B vertically?
    • A) A || B
    • B) A + B
    • C) [A; B]
    • D) [A B]
  18. What is the MATLAB function for the exponential of a matrix?
    • A) exp()
    • B) exponent()
    • C) power()
    • D) expm()
  19. What would the command linspace(1, 10, 5) generate?
    • A) 5 random numbers
    • B) 5 evenly spaced numbers from 1 to 10
    • C) 5 integers from 1 to 10
    • D) 10 numbers from 1 to 5
  20. How can you delete the first row of a matrix M?
    • A) M(1,:) = []
    • B) M(1) = []
    • C) delete(M(1,:))
    • D) remove(M(1,:))
  21. Which command is used to add a title to a plot?
    • A) title()
    • B) xlabel()
    • C) legend()
    • D) annotation()
  22. In MATLAB, which command is used to calculate the mean of an array?
    • A) average()
    • B) mean()
    • C) midpoint()
    • D) findmean()
  23. What does the command clc do in MATLAB?
    • A) Clears the command window
    • B) Clears variables
    • C) Closes figures
    • D) Clears the plot
  24. How can you execute a script file named script.m?
    • A) run script.m
    • B) execute script.m
    • C) script
    • D) run <script.m>
  25. Which operator is used for element-wise multiplication?
    • A) *
    • B) .
    • C) .*
    • D) element*
  26. In MATLAB, how is a string created?
    • A) “string”
    • B) ‘string’
    • C) string
    • D) {string}
  27. What would A = [1 2; 3 4]; B = A'; do?
    • A) Create matrix B as a transpose of A
    • B) Add A and B
    • C) Multiply A by B
    • D) Create an identity matrix
  28. Which command is used to plot a bar graph?
    • A) barplot()
    • B) bar()
    • C) histogram()
    • D) plotbar()
  29. How do you create a 3D plot in MATLAB?
    • A) plot3()
    • B) 3Dplot()
    • C) graph3()
    • D) plot3d()
  30. What command is used to find the determinant of a matrix?
    • A) det()
    • B) determinant()
    • C) matrixDet()
    • D) finddet()
  31. What does the command pause do in MATLAB?
    • A) Stops execution
    • B) Delays execution for a specified amount of time
    • C) Restarts execution
    • D) Continues execution
  32. How do you access the elements of a matrix M at row 2, column 1?
    • A) M(2, 1)
    • B) M[2][1]
    • C) M.2.1
    • D) M(1, 2)
  33. Which function in MATLAB is used to plot a histogram?
    • A) hist()
    • B) histogram()
    • C) hplot()
    • D) bar()
  34. What command would you use to add a grid to a plot?
    • A) grid()
    • B) addgrid()
    • C) gridon()
    • D) showgrid()
  35. How can you create a logical array in MATLAB?
    • A) [true, false]
    • B) (true, false)
    • C) {true, false}
    • D) <true, false>
  36. Which function is used to create a scatter plot?
    • A) scatterplot()
    • B) scatter()
    • C) plotscatter()
    • D) graphscatter()
  37. What does the command disp() do?
    • A) Displays a variable or message in the command window
    • B) Deletes a variable
    • C) Displays current variables
    • D) Discards a variable
  38. How can you convert a number to a string in MATLAB?
    • A) num2str()
    • B) str2num()
    • C) numberToString()
    • D) convertNum()
  39. Which command is used to check if a variable exists?
    • A) exists()
    • B) isvar()
    • C) ismember()
    • D) exist()
  40. How do you initialize a variable as an array with 10 zeros?
    • A) zeros(10)
    • B) array(10, 0)
    • C) [0,0,0,0,0,0,0,0,0,0]
    • D) zeros[10]
  41. What does the command axis equal do?
    • A) Sets the axis limits
    • B) Makes the scale of the axes equal
    • C) Equalizes the data points
    • D) Sets the axes to zero
  42. What is the scope of a variable defined inside a function?
    • A) Global
    • B) Local
    • C) Static
    • D) Default
  43. Which function would you use to calculate square roots in MATLAB?
    • A) sqrt()
    • B) root()
    • C) squareroot()
    • D) power(0.5)
  44. How do you append a value to a vector named vec?
    • A) vec = [vec, newValue]
    • B) append(vec, newValue)
    • C) add(vec, newValue)
    • D) vec.add(newValue)
  45. What is the purpose of the for loop in MATLAB?
    • A) To repeat code a specific number of times
    • B) To create functions
    • C) To control if-else statements
    • D) To perform data analysis
  46. What is the command to close all figure windows?
    • A) close all
    • B) close all()
    • C) figure close()
    • D) clearfigures()
  47. How do you plot sine wave values using the sin() function?
    • A) plot(sin(x))
    • B) sin(x)
    • C) plot(y)
    • D) sine(y)
  48. Which operator is used for scalar division?
    • A) /
    • B) ./
    • C) ./
    • D) div/
  49. What does isempty() function check in MATLAB?
    • A) If a variable is empty
    • B) If an array has no elements
    • C) Both A and B
    • D) If a matrix is singular
  50. What command would you use to sort an array in ascending order?
    • A) sortasc()
    • B) sort()
    • C) ascending()
    • D) order()