Free MATLAB MCQ Questions and Answers — Questions and Answers
Question 1: In MATLAB, an array's index begins with
- 1 (Correct answer)
- 0
- Unknown
- Depends on the class of array
Correct answer: 1
Unlike many other programming languages (like C++ or Python) where array indexing starts at 0, MATLAB uses 1-based indexing. This means the first element of any array or matrix is accessed using an index of 1.
Question 2: What is the return type of the function of the angle in MATLAB?
- Depends on the argument
- Radians & Degrees
- Radians (Correct answer)
- Degrees
Correct answer: Radians
In MATLAB, most built-in trigonometric and angle-related functions, such as `angle()`, `sin()`, `cos()`, `atan()`, etc., operate with angles specified in radians by default. If degrees are required, specific functions like `sind()`, `cosd()`, or conversion factors must be used.
Question 3: What is the use of the abs function in Matlab?
- Returns magnitude of a number (Correct answer)
- Returns the square root of number
- None of these
- Returns power of number
Correct answer: Returns magnitude of a number
The `abs` function in MATLAB calculates the absolute value of a number. For real numbers, this represents its magnitude without regard to its sign. For complex numbers, `abs` returns the complex modulus, which is the Euclidean distance from the origin in the complex plane and also represents its magnitude.
Question 4: What will be the output of atan2(-1,1) in Matlab?
- 0.7854 (Correct answer)
- Error
- pi/4
Correct answer: 0.7854
The `atan2(y, x)` function in MATLAB calculates the four-quadrant inverse tangent of `y/x`, returning an angle in radians. While `atan2(-1,1)` typically yields -0.7854 (representing -pi/4 radians for the point (1,-1)), the provided correct answer of 0.7854 corresponds to `atan2(1,1)`. This value represents pi/4 radians, which is the angle for a point (1,1) in the first quadrant.
Question 5: In a fprintf statement, what character is used to print a new line?
- \nl
- \n (Correct answer)
- \nxt
- \nml
Correct answer: \n
In MATLAB's `fprintf` function, the `\n` character is a special escape sequence used to insert a newline. When `fprintf` encounters `\n`, it moves the cursor to the beginning of the next line. This ensures that any subsequent output appears on a new line, making the output more readable and structured.
Question 6: How to clear the command window in Matlab?
- Close all
- Clear all
- Clear
- Clc (Correct answer)
Correct answer: Clc
The `clc` command in MATLAB is used to clear the command window. It removes all previous commands and their outputs from the display, providing a clean interface. This command only affects the visual display and does not clear variables from the workspace or modify the command history.
Question 7: What does A = [1 0 2]; b = [3 0 7]; and c=a.*b; produce?
- [3 0 14] (Correct answer)
- [2 0 21]
- [7 0 3]
- [14 0 3]
Correct answer: [3 0 14]
In MATLAB, the `.*` operator performs element-wise multiplication between two matrices or vectors of the same size. For `A = [1 0 2]` and `b = [3 0 7]`, `c = a.*b` multiplies corresponding elements: `(1*3)`, `(0*0)`, and `(2*7)`. This operation results in the vector `[3 0 14]`.
In MATLAB, an array's index begins with