Bird
Raised Fist0
MATLABdata~20 mins

Axis control and formatting in MATLAB - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Axis Mastery
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 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;
A[0 2]
B[0 6.2832]
C[-1 1]
D[0 3.1416]
Attempts:
2 left
💡 Hint
The axis function sets limits as [xmin xmax ymin ymax].
❓ Predict Output
intermediate
2: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'});
ALow, Medium, High
B10, 30, 50
C1, 2, 3
D10, 20, 30, 40, 50
Attempts:
2 left
💡 Hint
yticklabels replaces numeric tick labels with strings.
🔧 Debug
advanced
2: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]);
Ax and y vectors have different lengths
Baxis requires four values [xmin xmax ymin ymax], but only two are given
Cplot function syntax is incorrect
Daxis limits must be positive numbers only
Attempts:
2 left
💡 Hint
Check the number of elements inside the axis brackets.
🧠 Conceptual
advanced
2: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?
Aaxis equal
Baxis tight
Caxis manual
Daxis auto
Attempts:
2 left
💡 Hint
Think about how to stop MATLAB from adjusting axis limits automatically.
❓ Predict Output
expert
2: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);
A6
B5
C11
D10
Attempts:
2 left
💡 Hint
Count the numbers from 0 to 10 stepping by 2.

Practice

(1/5)
1. What does the MATLAB command axis([0 10 0 5]) do to a plot?
easy
A. Sets the x-axis limits from 0 to 10 and y-axis limits from 0 to 5
B. Sets the axis color to RGB values [0 10 0 5]
C. Creates a grid with 10 rows and 5 columns
D. Labels the axes with numbers 0, 10, 0, and 5

Solution

  1. Step 1: Understand the axis function input

    The axis function with a vector of four numbers sets axis limits: [xmin xmax ymin ymax].
  2. Step 2: Apply the given limits

    Here, [0 10 0 5] means x-axis from 0 to 10 and y-axis from 0 to 5.
  3. Final Answer:

    Sets the x-axis limits from 0 to 10 and y-axis limits from 0 to 5 -> Option A
  4. Quick Check:

    axis([xmin xmax ymin ymax]) = set axis limits [OK]
Hint: Remember axis([xmin xmax ymin ymax]) sets axis limits [OK]
Common Mistakes:
  • Confusing axis limits with colors
  • Thinking axis sets labels or grid size
  • Using axis without four numbers
2. Which of the following is the correct syntax to set the x-axis label to 'Time (s)' in MATLAB?
easy
A. labelx('Time (s)')
B. xlabel('Time (s)')
C. setxlabel('Time (s)')
D. xaxislabel('Time (s)')

Solution

  1. Step 1: Recall MATLAB function for x-axis label

    The function to set x-axis label is xlabel with the label text as input.
  2. Step 2: Check syntax correctness

    xlabel('Time (s)') correctly sets the label. Other options are invalid function names.
  3. Final Answer:

    xlabel('Time (s)') -> Option B
  4. Quick Check:

    Use xlabel('text') to label x-axis [OK]
Hint: Use xlabel('text') exactly to label x-axis [OK]
Common Mistakes:
  • Using wrong function names like setxlabel
  • Forgetting quotes around label text
  • Confusing xlabel with axis or title
3. What will be the effect of the following MATLAB code?
plot(1:5, [2 4 6 8 10]);
axis([0 6 0 12]);
xticks([0 2 4 6]);
yticks([0 6 12]);
medium
A. Plot points with x-axis from 0 to 6, y-axis from 0 to 12, x-ticks at 0,2,4,6 and y-ticks at 0,6,12
B. Plot points with default axis limits and ticks
C. Error because xticks and yticks require vectors of length 5
D. Plot with reversed axes limits

Solution

  1. Step 1: Analyze axis limits

    axis([0 6 0 12]) sets x-axis from 0 to 6 and y-axis from 0 to 12.
  2. Step 2: Analyze tick settings

    xticks([0 2 4 6]) sets x-axis ticks at 0, 2, 4, 6; yticks([0 6 12]) sets y-axis ticks at 0, 6, 12.
  3. Final Answer:

    Plot points with x-axis from 0 to 6, y-axis from 0 to 12, x-ticks at 0,2,4,6 and y-ticks at 0,6,12 -> Option A
  4. Quick Check:

    axis + xticks + yticks control limits and ticks [OK]
Hint: axis sets limits; xticks/yticks set tick marks [OK]
Common Mistakes:
  • Assuming default ticks remain after setting axis
  • Thinking xticks/yticks need same length as data
  • Confusing axis limits with tick positions
4. Identify the error in this MATLAB code snippet for setting axis limits and fix it:
plot(1:3, [5 10 15])
axis(0 3 0 20)
medium
A. Limits must be strings; use axis('0 3 0 20')
B. axis function does not set limits; use xlim and ylim instead
C. Missing square brackets around limits; should be axis([0 3 0 20])
D. No error; code runs fine

Solution

  1. Step 1: Check axis function syntax

    The axis function requires a vector input for limits, enclosed in square brackets.
  2. Step 2: Identify missing brackets

    The code uses axis(0 3 0 20) without brackets, causing syntax error.
  3. Final Answer:

    Missing square brackets around limits; should be axis([0 3 0 20]) -> Option C
  4. Quick Check:

    axis([xmin xmax ymin ymax]) needs brackets [OK]
Hint: Always use square brackets for axis limits [OK]
Common Mistakes:
  • Omitting brackets around axis limits
  • Using strings instead of numeric vectors
  • Confusing axis with xlim or ylim functions
5. You want to create a plot with x-axis from -5 to 5, y-axis from -10 to 10, and custom ticks every 2 units on both axes. Which MATLAB code correctly achieves this?
hard
A. plot(x,y); axis([-5 5 -10 10]); xticks([-5 2 5]); yticks([-10 2 10]);
B. plot(x,y); axis([-5 5 -10 10]); xticks(-5:5); yticks(-10:10);
C. plot(x,y); xlim([-5 5]); ylim([-10 10]); ticks([-5 5], [-10 10]);
D. plot(x,y); axis([-5 5 -10 10]); xticks(-5:2:5); yticks(-10:2:10);

Solution

  1. Step 1: Set axis limits correctly

    axis([-5 5 -10 10]) sets x-axis and y-axis limits as required.
  2. Step 2: Set ticks every 2 units

    xticks(-5:2:5) creates ticks at -5, -3, -1, 1, 3, 5; similarly for y-axis with yticks(-10:2:10).
  3. Step 3: Check other options

    plot(x,y); axis([-5 5 -10 10]); xticks([-5 2 5]); yticks([-10 2 10]); sets ticks incorrectly (missing intermediate values). plot(x,y); xlim([-5 5]); ylim([-10 10]); ticks([-5 5], [-10 10]); uses invalid ticks function. plot(x,y); axis([-5 5 -10 10]); xticks(-5:5); yticks(-10:10); sets ticks every 5 units, not 2.
  4. Final Answer:

    plot(x,y); axis([-5 5 -10 10]); xticks(-5:2:5); yticks(-10:2:10); -> Option D
  5. Quick Check:

    Use axis for limits and colon operator for ticks [OK]
Hint: Use colon operator for ticks: start:step:end [OK]
Common Mistakes:
  • Setting ticks with wrong intervals
  • Using non-existent ticks() function
  • Confusing axis limits with tick values
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard