0
0
MATLABdata~15 mins

Subplot for multiple panels in MATLAB - Mini Project: Build & Apply

Choose your learning style9 modes available
Subplot for multiple panels
📖 Scenario: You are creating a simple report with multiple charts to compare different data sets side by side.
🎯 Goal: Build a MATLAB script that creates a figure with multiple panels using subplot. Each panel will show a different plot.
📋 What You'll Learn
Create a vector of x values from 1 to 10
Create three different y vectors for three plots
Use subplot to create a 1 row by 3 columns layout
Plot each y vector against x in its own subplot panel
Add titles to each subplot
💡 Why This Matters
🌍 Real World
Scientists and engineers often compare multiple data sets side by side to see patterns or differences clearly.
💼 Career
Knowing how to organize multiple plots in one figure is useful for data analysis, reporting, and presentations in many technical jobs.
Progress0 / 4 steps
1
Create the x and y data vectors
Create a vector called x with values from 1 to 10 using 1:10. Then create three vectors called y1, y2, and y3 with these exact values: y1 = x, y2 = x.^2, and y3 = sqrt(x).
MATLAB
Need a hint?

Use the colon operator to create x. Use element-wise power . ^ for y2. Use sqrt function for y3.

2
Set up the subplot layout
Use subplot to create a figure with 1 row and 3 columns. Prepare the first subplot panel by calling subplot(1, 3, 1).
MATLAB
Need a hint?

The subplot function takes three arguments: rows, columns, and panel number.

3
Plot the data in each subplot
Plot y1 vs x in the first subplot using plot(x, y1). Then create the second subplot with subplot(1, 3, 2) and plot y2 vs x. Finally, create the third subplot with subplot(1, 3, 3) and plot y3 vs x.
MATLAB
Need a hint?

Use plot to draw lines. Remember to switch subplot panels before each plot.

4
Add titles to each subplot and display
Add titles to each subplot using title. For the first subplot, add title('Linear'). For the second, add title('Quadratic'). For the third, add title('Square Root'). Then run the script to display the figure.
MATLAB
Need a hint?

Use title right after each plot call to label the subplot.