Challenge - 5 Problems
MATLAB Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this variable assignment?
Consider the following MATLAB code snippet. What will be the value of
result after execution?MATLAB
a = 5; b = 3; result = a + b * 2;
Attempts:
2 left
💡 Hint
Remember the order of operations: multiplication before addition.
✗ Incorrect
In MATLAB, multiplication happens before addition. So b * 2 = 6, then a + 6 = 11.
❓ Predict Output
intermediate2:00remaining
What is the value of variable
x after this code?Look at this MATLAB code. What is the value stored in
x?MATLAB
x = 10; x = x + 5; x = x - 3;
Attempts:
2 left
💡 Hint
Follow each assignment step carefully.
✗ Incorrect
x starts at 10, then 10 + 5 = 15, then 15 - 3 = 12.
🔧 Debug
advanced2:00remaining
Identify the error in this variable assignment
This MATLAB code tries to assign a value but causes an error. What is the error?
MATLAB
1var = 10;
Attempts:
2 left
💡 Hint
Variable names must start with a letter in MATLAB.
✗ Incorrect
MATLAB variable names must begin with a letter, not a number.
❓ Predict Output
advanced2:00remaining
What is the output of this vector assignment?
What is the value of
v after running this MATLAB code?MATLAB
v = [1, 2, 3]; v(2) = 10;
Attempts:
2 left
💡 Hint
Indexing in MATLAB starts at 1.
✗ Incorrect
The second element of vector v is replaced by 10, so v becomes [1, 10, 3].
🧠 Conceptual
expert2:00remaining
How many variables are created after this code runs?
Consider this MATLAB code snippet. How many distinct variables exist in the workspace after execution?
MATLAB
a = 5; b = a; a = 10; c = b + a;
Attempts:
2 left
💡 Hint
Count each unique variable name assigned.
✗ Incorrect
Variables a, b, and c exist. b copies a's value before a changes.