8. Suppose you are analyzing the monthly temperature data for a region over a 5-month period. The temperature data for each month across different cities is stored in the following matrix:
$$
\text{temperature} = \begin{bmatrix}
22 & 28 & 32 & 35 & 25 \\
18 & 25 & 20 & 22 & 27 \\
30 & 32 & 33 & 31 & 29 \\
25 & 29 & 28 & 24 & 26
\end{bmatrix}
$$
This matrix represents the temperature readings (in Celsius) for 4 cities (rows) over 5 months (columns). Perform the following operations:
Given this matrix as defined, perform the following operations:
a. Write MATLAB code using vectorized operations to calculate the average temperature for each city over the 5-month period. The output should be a vector containing the average temperature for each city.
For the provided 'temperature' matrix, your result should be a vector like
[28.4, 22.4, 31.0, 26.4].
answer sheet
b. Write a MATLAB script that accomplishes the same task as part (a) using a for loop and an internal if-statement to check if the temperature for any city in a month is above 30°C before averaging.
answer sheet