MATLAB General MCQ 5 — Questions and Answers
Question 1: In MATLAB, what is the default data type for numeric values?
- int32
- float
- double (Correct answer)
- single
Correct answer: double
MATLAB stores numeric values as double-precision floating-point (double) by default unless explicitly specified otherwise.
Question 2: Which function would you use to plot a function y = sin(x) over the range [0, 2π] in MATLAB?
- x = 0:pi/100:2*pi; plot(x, sin(x)) (Correct answer)
- plot(sin, 0, 2*pi)
- draw(sin(x), [0 2*pi])
- graph(x=0:2*pi, sin(x))
Correct answer: x = 0:pi/100:2*pi; plot(x, sin(x))
You must first define a vector x with the desired range, then pass both x and sin(x) to the plot() function.
Question 3: What does 'NaN' represent in MATLAB?
- Negative absolute number
- Not a Number — an undefined or unrepresentable value (Correct answer)
- Null array notation
- Normalized approximate number
Correct answer: Not a Number — an undefined or unrepresentable value
NaN stands for Not a Number and results from undefined operations like 0/0 or Inf - Inf.
Question 4: How do you suppress output in MATLAB when executing a command?
- Wrap the command in quiet()
- Add a semicolon (;) at the end (Correct answer)
- Prefix with --silent
- Use nargout = 0
Correct answer: Add a semicolon (;) at the end
Appending a semicolon at the end of a statement suppresses the automatic display of its result in the Command Window.
Question 5: Which MATLAB function computes the Fast Fourier Transform of a signal?
- dft(x)
- fft(x) (Correct answer)
- fourier(x)
- spectrum(x)
Correct answer: fft(x)
fft(x) computes the discrete Fourier transform of vector x using the Fast Fourier Transform algorithm.
Question 6: What is the result of the MATLAB expression: [1 2 3] + [4; 5; 6]?
- [5 7 9]
- [5; 7; 9]
- A 3×3 matrix via broadcasting (Correct answer)
- An error due to dimension mismatch
Correct answer: A 3×3 matrix via broadcasting
In MATLAB R2016b+, implicit expansion (broadcasting) allows a 1×3 row vector and a 3×1 column vector to be added, producing a 3×3 matrix.
Question 7: Which MATLAB function saves workspace variables to a .mat file?
- export('file.mat')
- save('file.mat') (Correct answer)
- write('file.mat')
- store('file.mat')
Correct answer: save('file.mat')
The save function writes workspace variables to a binary .mat file, which can later be loaded with the load function.
In MATLAB, what is the default data type for numeric values?