Multiple Plots in MATLAB

📊 Multiple Plots in MATLAB
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→ rowsn→ columnsp→ 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 axessubplot()→ separate axesUse
legend()for clarityLabel 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 axessubplot() → 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 onoverlays graphssubplot()divides the windowEssential for data analysis & reporting
