Bird
0
0

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📝 Application Q15 of 15
MATLAB - 2D Plotting
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?
Asubplot(2,2); for k = 1:4 plot(sin(k*x)); end
Bfor k = 1:4 subplot(4,1,k); x = linspace(0,2*pi,100); plot(x, sin(k*x)); end
Cfor k = 1:4 subplot(2,2,k); x = linspace(0,2*pi,100); plot(x, sin(k*x)); end
Dfor k = 1:4 subplot(2,2,k+1); x = linspace(0,2*pi,100); plot(x, sin(k*x)); end
Step-by-Step Solution
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]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes