Challenge - 5 Problems
MATLAB Plot Label 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 MATLAB plot labeling code?
Consider the following MATLAB code that plots a simple line and adds labels and a title. What text will appear as the x-axis label?
MATLAB
x = 1:5; y = x.^2; plot(x, y); xlabel('Time (s)'); ylabel('Distance (m)'); title('Distance vs Time');
Attempts:
2 left
💡 Hint
Look for the function that sets the label for the x-axis.
✗ Incorrect
The function xlabel('Time (s)') sets the label for the x-axis to 'Time (s)'.
❓ Predict Output
intermediate2:00remaining
What legend text appears in this MATLAB plot?
Given this MATLAB code, what text will appear in the legend?
MATLAB
x = 0:0.1:2*pi; y1 = sin(x); y2 = cos(x); plot(x, y1, '-r', x, y2, '-b'); legend('Sine Wave', 'Cosine Wave');
Attempts:
2 left
💡 Hint
Check the legend function arguments.
✗ Incorrect
The legend function is called with 'Sine Wave' and 'Cosine Wave', so these exact texts appear in the legend.
🔧 Debug
advanced2:00remaining
Why does this MATLAB code not display the title?
This MATLAB code plots data and tries to add a title, but the title does not appear. What is the problem?
MATLAB
x = 1:10; y = rand(1,10); plot(x,y) title = 'Random Data Plot';
Attempts:
2 left
💡 Hint
Check how the title is set in MATLAB.
✗ Incorrect
The code assigns a string to a variable named title instead of calling the title() function, so no title is displayed.
🧠 Conceptual
advanced2:00remaining
What happens if you call legend without arguments after plotting multiple lines?
In MATLAB, after plotting multiple lines, what does calling legend() with no arguments do?
Attempts:
2 left
💡 Hint
Think about how MATLAB uses DisplayName properties in plots.
✗ Incorrect
Calling legend() without arguments uses the DisplayName properties of plotted lines to create a legend automatically.
❓ Predict Output
expert3:00remaining
What is the output of this MATLAB code with multiple labels and legend?
Analyze this MATLAB code and determine what text appears as the y-axis label and what the legend shows.
MATLAB
x = linspace(0,1,5); y1 = x; y2 = x.^2; plot(x,y1,'-o', x,y2,'-s'); ylabel('Value'); legend({'Linear','Quadratic'}); title('Comparison Plot');
Attempts:
2 left
💡 Hint
Check the ylabel and legend function arguments carefully.
✗ Incorrect
ylabel('Value') sets the y-axis label to 'Value'. legend({'Linear','Quadratic'}) sets the legend text accordingly.