Challenge - 5 Problems
Axis Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this axis limit setting?
Consider the following MATLAB code snippet that plots a sine wave and sets axis limits. What will be the x-axis limits after running this code?
MATLAB
x = linspace(0, 2*pi, 100); y = sin(x); plot(x, y); axis([0 pi -1 1]); xl = xlim;
Attempts:
2 left
💡 Hint
The axis function sets limits as [xmin xmax ymin ymax].
✗ Incorrect
The axis command sets the x-axis limits to 0 and pi (approximately 3.1416). The xlim function returns these limits.
❓ Predict Output
intermediate2:00remaining
What is the y-axis tick labels after formatting?
Given the code below, what will be the y-axis tick labels displayed on the plot?
MATLAB
y = [10 20 30 40 50]; plot(y); yticks([10 30 50]); yticklabels({'Low', 'Medium', 'High'});
Attempts:
2 left
💡 Hint
yticklabels replaces numeric tick labels with strings.
✗ Incorrect
The yticks function sets ticks at 10, 30, and 50. The yticklabels function replaces these numeric labels with 'Low', 'Medium', and 'High'.
🔧 Debug
advanced2:00remaining
Why does this axis command cause an error?
The following MATLAB code attempts to set axis limits but causes an error. Identify the cause.
MATLAB
x = 1:10; y = x.^2; plot(x, y); axis([0 10]);
Attempts:
2 left
💡 Hint
Check the number of elements inside the axis brackets.
✗ Incorrect
The axis function expects four values to set x and y limits. Providing only two values causes an error.
🧠 Conceptual
advanced2:00remaining
Which command freezes the axis limits to prevent automatic changes?
In MATLAB, after plotting data, which command prevents the axis limits from changing when new plots are added?
Attempts:
2 left
💡 Hint
Think about how to stop MATLAB from adjusting axis limits automatically.
✗ Incorrect
The 'axis manual' command freezes the current axis limits so they do not change when new data is plotted.
❓ Predict Output
expert2:00remaining
What is the number of x-axis ticks after this code runs?
Given the code below, how many tick marks will appear on the x-axis?
MATLAB
x = linspace(0, 10, 100); y = sin(x); plot(x, y); xticks(0:2:10);
Attempts:
2 left
💡 Hint
Count the numbers from 0 to 10 stepping by 2.
✗ Incorrect
The xticks command sets ticks at 0, 2, 4, 6, 8, and 10, which is 6 ticks total.