0
0
MATLABdata~20 mins

Colon operator for ranges in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Colon Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
Output of a simple colon operator range
What is the output of this MATLAB code?
a = 3:7;
MATLAB
a = 3:7;
A[7 6 5 4 3]
B[3 5 7]
C[3 4 5 6 7]
D[3 4 5 6]
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.
Predict Output
intermediate
1: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;
A[1 4 7]
B[1 3 5 7 9]
C[1 2 3 4 5 6 7 8 9]
D[2 4 6 8]
Attempts:
2 left
💡 Hint
The colon operator with three parts is start:step:end.
Predict Output
advanced
2: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;
A[0 0.3 0.6 0.9 1.2]
B[0 0.3 0.6]
C[0 0.3 0.6 0.9 1.0]
D[0 0.3 0.6 0.9]
Attempts:
2 left
💡 Hint
The colon operator stops before exceeding the end value.
Predict Output
advanced
1: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;
A[5 4 3 2 1]
B[1 2 3 4 5]
C[5 4 3 2]
D[5 6 7 8 9]
Attempts:
2 left
💡 Hint
The colon operator can count down if the step is negative.
🧠 Conceptual
expert
2: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;
A7
B6
C9
D8
Attempts:
2 left
💡 Hint
Count elements starting at 2, adding 0.5 until you reach or pass 5.