MATLAB Basic Introduction 2 — Questions and Answers
Question 1: Which MATLAB function displays output to the Command Window without suppressing it?
- disp()
- fprintf()
- Both disp() and fprintf() (Correct answer)
- print()
Correct answer: Both disp() and fprintf()
Both disp() and fprintf() print output to the Command Window, though fprintf() offers more formatting control.
Question 2: What does the semicolon (;) do when placed at the end of a MATLAB statement?
- Ends the script
- Suppresses output to the Command Window (Correct answer)
- Adds a comment
- Separates matrix rows
Correct answer: Suppresses output to the Command Window
A semicolon at the end of a statement suppresses its output from being printed to the Command Window.
Question 3: In MATLAB, what is the result of 5 \ 20?
- 0.25
- 4 (Correct answer)
- 100
- 15
Correct answer: 4
The left-division operator (\) computes 20/5 = 4, solving x such that 5*x = 20.
Question 4: How do you create a row vector of integers from 1 to 10 with step 2 in MATLAB?
- 1:2:10 (Correct answer)
- 1;2;10
- linspace(1,10,2)
- range(1,10,2)
Correct answer: 1:2:10
The colon syntax start:step:end creates a row vector; 1:2:10 produces [1 3 5 7 9].
Question 5: Which of the following correctly accesses the element in row 2, column 3 of matrix M?
- M[2,3]
- M(2,3) (Correct answer)
- M{2,3}
- M(3,2)
Correct answer: M(2,3)
MATLAB uses parentheses for indexing, so M(2,3) retrieves the element at row 2, column 3.
Question 6: What does the command 'clc' do in MATLAB?
- Clears all variables from the workspace
- Closes all open figures
- Clears the Command Window display (Correct answer)
- Closes MATLAB
Correct answer: Clears the Command Window display
clc clears the Command Window of all displayed text, but does not remove workspace variables.
Question 7: What is the MATLAB operator for element-wise multiplication of two arrays?
- *
- .* (Correct answer)
- x
- .x
Correct answer: .*
The .* operator performs element-wise multiplication, while * performs matrix multiplication.
Which MATLAB function displays output to the Command Window without suppressing it?