0
0
MATLABdata~20 mins

Labels, title, and legend in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
MATLAB Plot Label Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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');
ATime (s)
BDistance (m)
CDistance vs Time
Dx-axis
Attempts:
2 left
💡 Hint
Look for the function that sets the label for the x-axis.
Predict Output
intermediate
2: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');
Asin and cos
BSine Wave and Cosine Wave
CRed and Blue lines
DSine and Cosine
Attempts:
2 left
💡 Hint
Check the legend function arguments.
🔧 Debug
advanced
2: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';
AThe plot command is missing a semicolon
BThe x and y vectors have different lengths
CThe y data is not sorted
DThe title is assigned to a variable instead of calling the title() function
Attempts:
2 left
💡 Hint
Check how the title is set in MATLAB.
🧠 Conceptual
advanced
2: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?
AIt automatically creates a legend using the DisplayName properties of plotted lines
BIt clears any existing legend from the plot
CIt creates an empty legend box
DIt causes a syntax error
Attempts:
2 left
💡 Hint
Think about how MATLAB uses DisplayName properties in plots.
Predict Output
expert
3: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');
Ay-axis label: 'Comparison Plot'; legend: 'Linear' and 'Quadratic'
By-axis label: 'Value'; legend: 'y1' and 'y2'
Cy-axis label: 'Value'; legend: 'Linear' and 'Quadratic'
Dy-axis label: 'Value'; legend: 'o' and 's'
Attempts:
2 left
💡 Hint
Check the ylabel and legend function arguments carefully.