0
0
MATLABdata~20 mins

First MATLAB program - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
MATLAB First Program Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
Ax + y
B8
C53
DError: Undefined function or variable 'z'.
Attempts:
2 left
💡 Hint
Remember that disp shows the value of the variable, not the expression.
🧠 Conceptual
intermediate
2:00remaining
Understanding MATLAB script execution
Which statement best describes what happens when you run a MATLAB script file?
AMATLAB executes commands line by line in the script from top to bottom.
BMATLAB compiles the script into a standalone program before running.
CMATLAB runs all commands in the script simultaneously.
DMATLAB only checks the script for syntax errors but does not run it.
Attempts:
2 left
💡 Hint
Think about how you read a recipe or instructions.
🔧 Debug
advanced
2: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);
ANo error, output is 30
BSyntax error: Missing semicolon after first line
CRuntime error: Undefined variable 'a'
DSyntax error: Missing end statement
Attempts:
2 left
💡 Hint
In MATLAB, semicolons suppress output but are not required for correctness.
Predict Output
advanced
2: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);
AAlice is age years old.
BError: Cannot concatenate string and number directly.
CAlice is 25 years old.
DAlice is 25 years old
Attempts:
2 left
💡 Hint
num2str converts numbers to strings for concatenation.
🚀 Application
expert
2: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);
A6
BError: Logical indexing not allowed
C10
D5
Attempts:
2 left
💡 Hint
Think about which numbers in arr are greater than 5.