Challenge - 5 Problems
Colon Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
Output of a simple colon operator range
What is the output of this MATLAB code?
a = 3:7;
MATLAB
a = 3:7;
Attempts:
2 left
💡 Hint
The colon operator creates a vector starting at the first number and ending at the second, increasing by 1 by default.
✗ Incorrect
The colon operator a:b creates a row vector starting at a, ending at b, with step size 1. So 3:7 is [3 4 5 6 7].
❓ Predict Output
intermediate1:30remaining
Output with custom step size in colon operator
What is the output of this MATLAB code?
b = 1:2:9;
MATLAB
b = 1:2:9;
Attempts:
2 left
💡 Hint
The colon operator with three parts is start:step:end.
✗ Incorrect
1:2:9 means start at 1, add 2 each time, stop before exceeding 9. So the vector is [1 3 5 7 9].
❓ Predict Output
advanced2:00remaining
Output when step size does not evenly fit range
What is the output of this MATLAB code?
c = 0:0.3:1;
MATLAB
c = 0:0.3:1;
Attempts:
2 left
💡 Hint
The colon operator stops before exceeding the end value.
✗ Incorrect
Starting at 0, adding 0.3 each time: 0, 0.3, 0.6, 0.9, next would be 1.2 which is >1, so stop at 0.9.
❓ Predict Output
advanced1:30remaining
Output of colon operator with negative step
What is the output of this MATLAB code?
d = 5:-1:1;
MATLAB
d = 5:-1:1;
Attempts:
2 left
💡 Hint
The colon operator can count down if the step is negative.
✗ Incorrect
5:-1:1 counts down from 5 to 1 by subtracting 1 each step, so the vector is [5 4 3 2 1].
🧠 Conceptual
expert2:00remaining
Number of elements in colon operator range
How many elements are in the vector created by this MATLAB code?
e = 2:0.5:5;
MATLAB
e = 2:0.5:5;
Attempts:
2 left
💡 Hint
Count elements starting at 2, adding 0.5 until you reach or pass 5.
✗ Incorrect
Elements are 2, 2.5, 3, 3.5, 4, 4.5, 5.0. That's 7 elements, so answer is 7.