Multiple Outputs in MATLAB Functions
📖 Scenario: Imagine you are analyzing sales data for a small store. You want to write a MATLAB function that calculates both the total sales and the average sale amount from a list of sales.
🎯 Goal: Create a MATLAB function that takes a list of sales amounts and returns two outputs: the total sales and the average sale amount.
📋 What You'll Learn
Create a vector called
sales with the exact values: 100, 200, 150, 300, 250Create a variable called
numSales that stores the number of salesWrite a function called
calculateSales that takes sales as input and returns two outputs: totalSales and averageSaleCall the function
calculateSales with sales and store the outputs in variables total and averagePrint the values of
total and average💡 Why This Matters
🌍 Real World
Stores and businesses often analyze sales data to understand total revenue and average purchase size, helping them make better decisions.
💼 Career
Data analysts and scientists frequently write functions that return multiple results to summarize data efficiently.
Progress0 / 4 steps