MATLAB Basic Introduction 5 — Questions and Answers
Question 1: Which MATLAB function is used to find the maximum value in a vector?
- maximum(v)
- max(v) (Correct answer)
- top(v)
- largest(v)
Correct answer: max(v)
max(v) returns the largest element in vector v, and can also return its index as a second output.
Question 2: What does the command 'format long' change in MATLAB?
- Increases loop execution time
- Displays more decimal digits in numeric output (Correct answer)
- Changes the font size
- Enables long variable names
Correct answer: Displays more decimal digits in numeric output
format long switches display to 15 significant digits instead of MATLAB's default 4-digit short format.
Question 3: How do you transpose a matrix A in MATLAB?
- transpose(A)
- A'
- A.T
- Both transpose(A) and A' (Correct answer)
Correct answer: Both transpose(A) and A'
Both A' (conjugate transpose) and transpose(A) transpose the matrix; for real matrices they produce the same result.
Question 4: What is the output of mod(10, 3) in MATLAB?
- 3
- 1 (Correct answer)
- 0
- 3.33
Correct answer: 1
mod(10,3) returns 1 because 10 = 3×3 + 1, so the remainder is 1.
Question 5: Which file extension is used for MATLAB script files?
- .mat
- .ml
- .m (Correct answer)
- .mlab
Correct answer: .m
MATLAB script and function files use the .m extension, while .mat files store workspace data.
Question 6: What happens when you type a variable name in the Command Window without a semicolon?
- The variable is deleted
- MATLAB prints the variable's value (Correct answer)
- An error is thrown
- The variable is redefined as zero
Correct answer: MATLAB prints the variable's value
Without a semicolon, MATLAB echoes the variable's name and current value to the Command Window.
Question 7: Which MATLAB function generates a vector of n evenly spaced points between a and b?
- range(a, b, n)
- linspace(a, b, n) (Correct answer)
- space(a, b, n)
- evenly(a, b, n)
Correct answer: linspace(a, b, n)
linspace(a, b, n) creates a row vector of n linearly spaced values from a to b inclusive.
Which MATLAB function is used to find the maximum value in a vector?