Recall & Review
beginner
What does the colon operator (:) do in MATLAB when used like this: 1:5?
It creates a row vector with values starting at 1, increasing by 1, up to 5. So, the result is [1 2 3 4 5].
Click to reveal answer
beginner
How do you use the colon operator to create a vector from 2 to 10 with a step size of 2?
You write 2:2:10. This means start at 2, add 2 each time, until you reach or pass 10. The result is [2 4 6 8 10].
Click to reveal answer
intermediate
What happens if the step size in the colon operator is negative, like 5:-1:1?
It creates a vector starting at 5, decreasing by 1 each time, down to 1. So, the vector is [5 4 3 2 1].
Click to reveal answer
intermediate
Can the colon operator create an empty vector? If yes, give an example.
Yes. For example, 1:-1:5 creates an empty vector because starting at 1 and decreasing by 1 will never reach 5. So, the result is [].
Click to reveal answer
beginner
Explain the difference between 1:5 and 1:1:5 in MATLAB.
Both create the same vector [1 2 3 4 5]. The first uses the default step size of 1, while the second explicitly sets the step size to 1.
Click to reveal answer
What is the result of 3:3:12 in MATLAB?
✗ Incorrect
Starting at 3, adding 3 each time until 12 gives [3 6 9 12].
What does the expression 10:-2:2 produce?
✗ Incorrect
Starting at 10, subtracting 2 each time down to 2 results in [10 8 6 4 2].
What happens if you run 1:0:5 in MATLAB?
✗ Incorrect
A step size of zero is invalid and causes an error.
Which of these creates an empty vector?
✗ Incorrect
Starting at 1 and decreasing by 1 will never reach 5, so the vector is empty.
What is the default step size when using the colon operator like 4:9?
✗ Incorrect
If no step size is given, MATLAB uses 1 by default.
Describe how to use the colon operator to create a vector with a custom step size.
Think about how you tell MATLAB where to start, how much to jump each time, and where to stop.
You got /5 concepts.
Explain what happens when the step size in the colon operator does not allow reaching the end value.
Consider if the step moves away from the end value instead of towards it.
You got /4 concepts.