0
0
MATLABdata~15 mins

Labels, title, and legend in MATLAB - Mini Project: Build & Apply

Choose your learning style9 modes available
Labels, title, and legend
📖 Scenario: You are analyzing sales data for two products over a week. You want to create a clear line plot to compare their sales trends.
🎯 Goal: Create a line plot with sales data for two products. Add labels for the x-axis and y-axis, a title for the plot, and a legend to identify each product's line.
📋 What You'll Learn
Create vectors for days and sales data for two products
Add x-axis label as 'Day of Week'
Add y-axis label as 'Sales Units'
Add a title 'Weekly Sales Comparison'
Add a legend with labels 'Product A' and 'Product B'
💡 Why This Matters
🌍 Real World
In business, clear charts help teams understand sales trends quickly and make better decisions.
💼 Career
Data analysts and scientists often create plots with labels, titles, and legends to communicate insights clearly.
Progress0 / 4 steps
1
Create sales data vectors
Create a vector called days with values from 1 to 7 representing days of the week. Create two vectors called salesA and salesB with these exact values: salesA = [50 60 55 70 65 80 75] and salesB = [45 55 60 65 70 75 85].
MATLAB
Need a hint?

Use the colon operator to create days. Assign the exact arrays for salesA and salesB.

2
Plot the sales data
Use the plot function to plot salesA and salesB against days. Use different line styles or colors for each product. Use hold on to plot both lines on the same figure.
MATLAB
Need a hint?

Plot salesA first, then use hold on before plotting salesB.

3
Add labels and title
Add an x-axis label with xlabel('Day of Week'), a y-axis label with ylabel('Sales Units'), and a title with title('Weekly Sales Comparison').
MATLAB
Need a hint?

Use xlabel, ylabel, and title functions with the exact text.

4
Add a legend and display the plot
Add a legend with labels 'Product A' and 'Product B' using the legend function. Then use hold off to finish the plot. Finally, display the plot by running the script.
MATLAB
Need a hint?

Use legend with the exact labels and then hold off to finish.