Element-wise Operations in MATLAB
📖 Scenario: Imagine you have two lists of numbers representing daily sales and daily costs for a small shop. You want to calculate the profit for each day by subtracting costs from sales, then find the profit margin by dividing profit by sales, and finally calculate the profit growth by squaring the profit values.
🎯 Goal: You will create two vectors for sales and costs, then use element-wise operations .*, ./, and .^ to calculate profit, profit margin, and profit growth for each day.
📋 What You'll Learn
Create two vectors called
sales and costs with exact valuesCreate a variable called
days to store the number of daysCalculate
profit using element-wise subtractionCalculate
profit_margin using element-wise divisionCalculate
profit_growth using element-wise powerDisplay the results using
disp💡 Why This Matters
🌍 Real World
Element-wise operations are useful when you want to perform calculations on each item in a list or array separately, like calculating daily profits or growth rates.
💼 Career
Understanding element-wise operations is important for data analysis, financial modeling, and scientific computing where you work with arrays of data.
Progress0 / 4 steps