MATLAB General MCQ 3 — Questions and Answers
Question 1: In MATLAB, what does the function strcmp(s1, s2) return?
- The difference between two strings
- 1 if strings are equal, 0 otherwise (Correct answer)
- A sorted combination of both strings
- The index of the first differing character
Correct answer: 1 if strings are equal, 0 otherwise
strcmp returns logical 1 (true) if s1 and s2 are identical, and logical 0 (false) otherwise.
Question 2: Which MATLAB function converts a numeric value to a string?
- str2num
- char
- num2str (Correct answer)
- int2str
Correct answer: num2str
num2str converts a numeric array to a character array (string), with optional format control.
Question 3: What does the MATLAB function isempty(A) return when A = []?
- 0
- NaN
- 1 (Correct answer)
- Inf
Correct answer: 1
isempty returns 1 (true) when the array has any dimension of size zero, such as an empty matrix [].
Question 4: Which statement correctly defines an anonymous function for f(x) = x^2 + 1 in MATLAB?
- f = function(x) x^2 + 1
- f = @(x) x^2 + 1 (Correct answer)
- f(x) = x^2 + 1
- def f(x): x**2 + 1
Correct answer: f = @(x) x^2 + 1
Anonymous functions in MATLAB are created with the @ operator followed by the argument list and expression.
Question 5: What is the result of logical expression (3 > 2) & (5 < 4) in MATLAB?
- 1
- 0 (Correct answer)
- true
- Error
Correct answer: 0
The & operator is element-wise AND; (3>2) is true and (5<4) is false, so true & false = 0.
Question 6: Which MATLAB function computes the eigenvalues and eigenvectors of a square matrix?
- svd(A)
- eig(A) (Correct answer)
- det(A)
- inv(A)
Correct answer: eig(A)
eig(A) returns the eigenvalues of A, and [V,D] = eig(A) returns eigenvectors V and diagonal eigenvalue matrix D.
Question 7: What does the MATLAB command 'whos' display?
- The current working directory
- A list of current workspace variables with size, bytes, and class (Correct answer)
- All installed toolboxes
- The command history
Correct answer: A list of current workspace variables with size, bytes, and class
whos lists all variables in the current workspace along with their size, bytes, and data class.
In MATLAB, what does the function strcmp(s1, s2) return?