Challenge - 5 Problems
MATLAB First Program Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple MATLAB script
What is the output of this MATLAB code when run in the command window?
MATLAB
x = 5; y = 3; z = x + y; disp(z);
Attempts:
2 left
💡 Hint
Remember that disp shows the value of the variable, not the expression.
✗ Incorrect
The code adds x and y (5 + 3) and stores in z, then displays z, which is 8.
🧠 Conceptual
intermediate2:00remaining
Understanding MATLAB script execution
Which statement best describes what happens when you run a MATLAB script file?
Attempts:
2 left
💡 Hint
Think about how you read a recipe or instructions.
✗ Incorrect
MATLAB runs scripts line by line in order, executing each command sequentially.
🔧 Debug
advanced2:00remaining
Identify the error in this MATLAB code
What error will this MATLAB code produce when run?
MATLAB
a = 10 b = 20; c = a + b; disp(c);
Attempts:
2 left
💡 Hint
In MATLAB, semicolons suppress output but are not required for correctness.
✗ Incorrect
MATLAB allows lines without semicolons; it will display the value of 'a' but no error occurs.
❓ Predict Output
advanced2:00remaining
Output of a MATLAB script with string and numeric variables
What will be displayed when this MATLAB code runs?
MATLAB
name = 'Alice'; age = 25; message = [name, ' is ', num2str(age), ' years old.']; disp(message);
Attempts:
2 left
💡 Hint
num2str converts numbers to strings for concatenation.
✗ Incorrect
The code converts age to string and concatenates with name and other text, then displays the full message.
🚀 Application
expert2:00remaining
Number of elements in a MATLAB array after operations
Consider this MATLAB code. How many elements does the variable 'result' contain after execution?
MATLAB
arr = 1:10; result = arr(arr > 5);
Attempts:
2 left
💡 Hint
Think about which numbers in arr are greater than 5.
✗ Incorrect
arr > 5 is true for elements 6,7,8,9,10, so result contains 5 elements.