Bird
Raised Fist0
MATLABdata~5 mins

Subplot for multiple panels in MATLAB - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What does the subplot function do in MATLAB?
It divides the figure window into a grid of smaller axes (panels) and selects one for plotting.
Click to reveal answer
beginner
How do you create a 2-by-3 grid of plots and select the 4th panel?
Use subplot(2, 3, 4). This means 2 rows, 3 columns, and the 4th panel is active.
Click to reveal answer
intermediate
What happens if you call subplot multiple times with the same position?
The new plot replaces the old one in that panel, clearing previous content.
Click to reveal answer
beginner
How can you add a title to each subplot panel?
After calling subplot, use title('Your Title') to add a title to that panel.
Click to reveal answer
intermediate
How to create a 2x2 subplot and plot different data in each panel?
Call subplot(2,2,i) for i=1 to 4, then plot data in each selected panel separately.
Click to reveal answer
What does subplot(3,1,2) do?
ACreates a grid with 3 rows, 1 column, and selects the 2nd panel
BCreates a grid with 1 row, 3 columns, and selects the 2nd panel
CCreates a grid with 3 rows, 1 column, and selects the 3rd panel
DCreates a grid with 2 rows, 3 columns, and selects the 1st panel
If you want 4 plots in one figure arranged in 2 rows and 2 columns, which command is correct to select the last panel?
Asubplot(1,4,4)
Bsubplot(2,2,4)
Csubplot(4,1,2)
Dsubplot(2,4,4)
What happens if you plot twice on the same subplot without holding on?
AThe second plot replaces the first
BBoth plots appear together
CAn error occurs
DThe figure window closes
How do you add a title to a specific subplot?
AUse <code>figure</code> to add a title
BUse <code>subplot</code> with a title argument
CCall <code>title</code> after selecting the subplot
DTitles cannot be added to subplots
Which command creates a 3x2 grid of subplots?
Asubplot(1,6,1)
Bsubplot(2,3,1)
Csubplot(6,1,1)
Dsubplot(3,2,1)
Explain how to create multiple panels in one figure using subplot in MATLAB.
Think of dividing a window into smaller boxes and drawing in each box.
You got /3 concepts.
    Describe how to add titles and labels to individual subplot panels.
    Each panel is like a mini-plot with its own decorations.
    You got /3 concepts.

      Practice

      (1/5)
      1. What does the MATLAB function subplot(2, 3, 4) do?
      easy
      A. Plots data in the 2nd row and 3rd column of a figure.
      B. Creates a 2x3 matrix and fills it with the number 4.
      C. Clears the 4th subplot in a 2 by 3 grid.
      D. Divides the figure into 2 rows and 3 columns, then selects the 4th panel for plotting.

      Solution

      1. Step 1: Understand subplot grid parameters

        The first two numbers (2, 3) define the grid size: 2 rows and 3 columns.
      2. Step 2: Identify the panel number

        The third number (4) selects the 4th panel in row-wise order for plotting.
      3. Final Answer:

        Divides the figure into 2 rows and 3 columns, then selects the 4th panel for plotting. -> Option D
      4. Quick Check:

        subplot(m, n, p) = grid m x n, panel p [OK]
      Hint: Remember subplot(m,n,p) means m rows, n columns, p panel [OK]
      Common Mistakes:
      • Confusing the order of rows and columns
      • Thinking subplot creates a matrix of numbers
      • Assuming subplot clears panels automatically
      2. Which of the following is the correct syntax to create a 3x1 subplot and plot in the second panel?
      easy
      A. subplot(3, 1, 2); plot(x, y);
      B. subplot(1, 3, 2); plot(x, y);
      C. subplot(3, 2, 1); plot(x, y);
      D. subplot(2, 3, 2); plot(x, y);

      Solution

      1. Step 1: Identify the grid layout

        A 3x1 subplot means 3 rows and 1 column, so subplot(3, 1, p) is correct.
      2. Step 2: Select the second panel

        The third argument '2' selects the second panel in the vertical stack.
      3. Final Answer:

        subplot(3, 1, 2); plot(x, y); -> Option A
      4. Quick Check:

        3 rows, 1 column, panel 2 = subplot(3,1,2) [OK]
      Hint: Rows first, then columns, then panel number [OK]
      Common Mistakes:
      • Swapping rows and columns in subplot arguments
      • Using wrong panel number for desired position
      • Confusing subplot grid with plot commands
      3. What will be the output of the following MATLAB code?
      subplot(1,2,1); plot(1:3, [2 4 6]);
      subplot(1,2,2); plot(1:3, [1 3 5]);
      medium
      A. Two plots side by side: first with points (1,2),(2,4),(3,6), second with (1,1),(2,3),(3,5).
      B. One plot with both data sets overlaid.
      C. Error because subplot indices are incorrect.
      D. Two plots stacked vertically.

      Solution

      1. Step 1: Understand subplot grid

        subplot(1,2,1) creates a grid with 1 row and 2 columns, selecting the first panel.
      2. Step 2: Plot data in each panel

        The first plot shows points (1,2), (2,4), (3,6). The second subplot(1,2,2) plots points (1,1), (2,3), (3,5).
      3. Final Answer:

        Two plots side by side: first with points (1,2),(2,4),(3,6), second with (1,1),(2,3),(3,5). -> Option A
      4. Quick Check:

        subplot(1,2,p) = two side-by-side plots [OK]
      Hint: subplot(1,2,p) means two plots side by side [OK]
      Common Mistakes:
      • Thinking plots overlay in one panel
      • Assuming vertical stacking instead of horizontal
      • Misreading subplot indices
      4. Identify the error in this MATLAB code snippet:
      subplot(2,2,5);
      plot(rand(5));
      medium
      A. plot function cannot be used inside subplot.
      B. Panel index 5 is invalid for a 2x2 grid.
      C. Missing semicolon after subplot command.
      D. rand(5) is incorrect syntax.

      Solution

      1. Step 1: Check subplot grid size

        A 2x2 grid has only 4 panels numbered 1 to 4.
      2. Step 2: Validate panel index

        Using 5 as the panel index is invalid and causes an error.
      3. Final Answer:

        Panel index 5 is invalid for a 2x2 grid. -> Option B
      4. Quick Check:

        Panel number must be ≤ rows*columns [OK]
      Hint: Panel number must not exceed total grid cells [OK]
      Common Mistakes:
      • Using panel number larger than grid size
      • Thinking semicolon affects subplot indexing
      • Believing plot can't be inside subplot
      5. You want to create a 2x2 grid of plots showing sine waves with different frequencies. Which code correctly sets up the subplots and plots the waves?
      hard
      A. subplot(2,2); for k = 1:4 plot(sin(k*x)); end
      B. for k = 1:4 subplot(4,1,k); x = linspace(0,2*pi,100); plot(x, sin(k*x)); end
      C. for k = 1:4 subplot(2,2,k); x = linspace(0,2*pi,100); plot(x, sin(k*x)); end
      D. for k = 1:4 subplot(2,2,k+1); x = linspace(0,2*pi,100); plot(x, sin(k*x)); end

      Solution

      1. Step 1: Set up correct subplot grid

        subplot(2,2,k) correctly creates a 2x2 grid and selects each panel from 1 to 4.
      2. Step 2: Plot sine waves with increasing frequency

        Inside the loop, x is defined and sin(k*x) is plotted in each subplot panel.
      3. Step 3: Check other options for errors

        for k = 1:4 subplot(4,1,k); x = linspace(0,2*pi,100); plot(x, sin(k*x)); end uses 4x1 grid, not 2x2. subplot(2,2); for k = 1:4 plot(sin(k*x)); end calls subplot once without panel index. for k = 1:4 subplot(2,2,k+1); x = linspace(0,2*pi,100); plot(x, sin(k*x)); end uses k+1 which causes invalid panel 5.
      4. Final Answer:

        for k = 1:4 subplot(2,2,k); x = linspace(0,2*pi,100); plot(x, sin(k*x)); end -> Option C
      5. Quick Check:

        Loop with subplot(2,2,k) plots 4 panels correctly [OK]
      Hint: Use subplot(2,2,k) inside loop k=1 to 4 [OK]
      Common Mistakes:
      • Using wrong subplot grid size
      • Not specifying panel index in subplot
      • Using invalid panel numbers
      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