0
0
MATLABdata~15 mins

Multiple plots (hold on) in MATLAB - Mini Project: Build & Apply

Choose your learning style9 modes available
Multiple plots using hold on in MATLAB
📖 Scenario: You are working on a simple data visualization project where you want to compare two sets of data on the same graph. This is common when you want to see how two trends relate to each other over the same range.
🎯 Goal: Build a MATLAB script that plots two different lines on the same graph using hold on. This will help you visualize both data sets together clearly.
📋 What You'll Learn
Create two vectors of data points
Plot the first data set using the plot function
Use hold on to keep the first plot visible
Plot the second data set on the same graph
Add labels for the x-axis and y-axis
Add a legend to distinguish the two plots
💡 Why This Matters
🌍 Real World
Plotting multiple data sets on the same graph is useful in science, engineering, and business to compare trends and relationships clearly.
💼 Career
Data visualization skills like plotting multiple lines help in roles such as data analyst, engineer, and researcher to communicate insights effectively.
Progress0 / 4 steps
1
Create the data vectors
Create two vectors called x and y1. Set x to the values [1 2 3 4 5] and y1 to the values [2 4 6 8 10].
MATLAB
Need a hint?

Use square brackets to create vectors in MATLAB, like x = [1 2 3].

2
Add the second data vector
Create a second vector called y2 with the values [1 3 5 7 9].
MATLAB
Need a hint?

Remember to use square brackets to create the vector.

3
Plot the first data set and hold the plot
Use plot(x, y1) to plot the first data set. Then use hold on to keep the plot active for adding more data.
MATLAB
Need a hint?

Use plot(x, y1) to draw the first line and hold on to keep the figure ready for more plots.

4
Plot the second data set and add labels and legend
Plot the second data set using plot(x, y2). Then add x-axis label 'X values', y-axis label 'Y values', and a legend with labels 'Data 1' and 'Data 2'. Finally, use hold off to finish plotting.
MATLAB
Need a hint?

Use xlabel, ylabel, and legend functions to add descriptions. Use hold off to stop adding plots.