Multiple Plots in MATLAB

MATLAB Tutorial

📊 Multiple Plots in MATLAB

Multiple plots in MATLAB allow you to display more than one graph in the same figure window.

This is useful for comparison, analysis, and visualization of related data.
MATLAB is developed by MathWorks.


🔹 Why Use Multiple Plots?

  • Compare different datasets

  • Visualize relationships clearly

  • Save screen space

  • Analyze multiple signals together


1️⃣ Multiple Plots Using hold on

Used to draw multiple graphs on the same axes.

🔸 Example


 

Output:
Sine and cosine curves on the same graph.

📌 hold on keeps the current plot, hold off releases it.


2️⃣ Multiple Plots Using plot() in One Command


Output:
Two curves plotted together.


3️⃣ Multiple Plots Using subplot()

subplot() divides the figure window into a grid.

🔸 Syntax


  • m → rows

  • n → columns

  • p → plot number


🔸 Example: 2×2 Subplots


 

Output:
Four different plots in one window.


4️⃣ Combining subplot() with Labels


 


5️⃣ Using tiledlayout (Modern MATLAB – Optional)

A newer and cleaner alternative to subplot().


 

📌 Preferred in new MATLAB versions.


⚠️ Important Notes

  • hold on → same axes

  • subplot() → separate axes

  • Use legend() for clarity

  • Label each plot properly


🎯 Interview Questions: Multiple Plots in MATLAB

🔹 Q1. How do you plot multiple lines on the same graph?

Answer:
Using hold on or a single plot() command.


🔹 Q2. What does subplot(2,2,3) mean?

Answer:
A 2×2 grid, third plot position.


🔹 Q3. Difference between hold on and subplot()?

Answer:
hold on → same axes
subplot() → different axes


🔹 Q4. Which function adds labels to multiple plots?

Answer:
xlabel(), ylabel(), title()


🔹 Q5. What is tiledlayout?

Answer:
A modern method to manage multiple plots neatly.


🔹 Q6. Can multiple plots be shown in one figure?

Answer:
Yes, using subplot() or hold on.


Summary

  • Multiple plots improve comparison

  • hold on overlays graphs

  • subplot() divides the window

  • Essential for data analysis & reporting

You may also like...