0% found this document useful (0 votes)
27 views5 pages

Calculating Statistics On Matrices

The document discusses calculating statistics on a matrix of oven temperature data to determine the best locations within the oven to cook pizzas. It shows how to split the oven temperature matrix into four quadrants and calculate the mean and standard deviation of each quadrant to compare their temperature ranges and consistency.

Uploaded by

thesis.companion
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views5 pages

Calculating Statistics On Matrices

The document discusses calculating statistics on a matrix of oven temperature data to determine the best locations within the oven to cook pizzas. It shows how to split the oven temperature matrix into four quadrants and calculate the mean and standard deviation of each quadrant to compare their temperature ranges and consistency.

Uploaded by

thesis.companion
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Calculating Statistics on Matrices

Previously, you worked with matrix data to create a map of oven temperatures. Now we would like to use the
map to help make decisions. For example, where should we place pizzas within the oven to ensure consistent
cooking? To answer this, we'll need to calculate some statistics.

In this reading, we will apply statistical functions to the oven temperatures to find the best spots in the oven to
cook pizzas. Let's start by loading the oven temperatures data.

load ovenTempsCorrected.mat ovenTemps

To visualize the temperature distribution in the oven, plot the temperatures using surf.

surf(ovenTemps)
xlabel("Oven Width")
ylabel("Oven Depth")
zlabel("Temperature (°C)")
colorbar

The temperature inside the oven varies between 240°C to 300°C. Considering the oven can fit 8 pizzas, it may
be practical to cook 4 pizzas in the oven at one time and still have ample space to move pizzas around.

Splitting up the oven


Therefore, let's split the oven up into four regions. Our task is to identify which quadrants have a temperature
range consistently within the range for cooking pizzas, which for our pizzas is 260°C to 290°C.

We create the quadrants by indexing our four matrices from the matrix ovenTemps. For example, here is the
code for quadrant 1.

quad1 = ovenTemps(1:6,1:8);

1
Now it's your turn. Write the lines of code to create quad2, quad3, and quad4 by indexing the columns and
rows shown in the previous graphic.

Calculating mean and standard deviation


Let's calculate the average value within the 1st quadrant. What happens when we pass quad1 to the mean
function?

mean(quad1)

The function returned a vector of 8 values. That's because statistical functions like mean return a value for each
column by default. There are 8 values because quad1 has 8 columns. To say this another way, the calculation is
applied across the 1st dimension, which are the rows of the matrix.

What do the values tell us? The mean values are all fairly uniform around 260°C, which is near the lower end
of our range. This consistency is slightly misleading, which we can see when we plot the values. The function
plot works similarly to statistical functions with matrices because it creates a line for each column.

plot(quad1)
xlabel("Row Index")
ylabel("Temperature (°C)")
title("Temperatures of Each Column in quad1")

The trend for each column is similar, but the range is large. One way to see this spread is with the statistical
function std for standard deviation (SD).

std(quad1)

2
A common way to report the average value is the mean ± SD. Therefore, we can report the first column of
quad1 has an average temperature of 258 ± 12 °C. This is definitely on the lower end of our desired range, but
it means some parts of quad1 would be above the required temperature of 260 °C.

What is the mean ± SD for the first column in quadrant 3? Try using the same statistical functions on quad3 to
find out. Is the average temperature in quad3 higher or lower than in quad1?

Specifying a dimension
Calculating a value for each column is useful, but how do we calculate a value for each row? Or across both
rows and columns? To do so, we specify the dimension as an input to the statistical functions. A value of 1 will
apply the mean across rows, returning a value for each column (like the default). A value of 2 will apply the
mean across the columns, returning a value for each row.

Let's calculate the mean temperature of each row in quad1. The function returns a vector with 6 values.

mean(quad1,2)

These values have a larger range, which we can confirm by plotting each row. Since the plot function creates
a line for each column, we transpose the matrix to invert the dimensions.

plot(quad1')
xlabel("Column Index")
ylabel("Temperature (°C)")
title("Temperatures of Each Row in quad1")

These lines are fairly flat, indicating not much variation within each row. However, there is a significant difference
between the rows in quad1. The 1st row with a mean of 234 °C is the blue line at the bottom of the plot.

Finally, we calculate the mean across both dimensions by using the string "all".

3
mean(quad1,"all")

We also specify the dimension with the std function, but as the third input. The second input is the weighting
scheme, or normalization factor, used to calculate the standard deviation. See the documentation for more
details. The default weight is 0, which is fine for our purposes. Let's use this value to find the standard deviation
of all the values in quad1.

std(quad1,0,"all")

Given these values, we can report the temperature within the first quadrant is around 259 ± 12 °C.

What's the overall mean ± SD for quad2? Does the range overlap with the values we calculated for quad1?

Comparing quadrants
Now we have all the pieces to compare the average and spread of temperatures in each quadrant. We first
calculate the values, and then we organize them by placing them in a vector.

quadrantMean = [mean(quad1,"all") mean(quad2,"all") ...


mean(quad3,"all") mean(quad4,"all")]

Let's repeat the same calculation for the standard deviations. Create a new vector named quadrantSpread
containing the overall standard deviation in each quadrant.

From these values, we can compare the approximate average temperatures and their spread. Replace the blank
spots below with rounded values in the vector quadrantSpread.

• quad1: 259 ± __ °C
• quad2: 267 ± __ °C
• quad3: 271 ± __ °C
• quad4: 281 ± __ °C

4
To visualize the values, let's use the function errorbar. We include the standard deviation values as error bar
heights in order to easily compare the mean values. We also use the functions xlim and xticks to improve
the appearance of the plot. The function xlim uses an input vector to define the x-axis limits, and the function
xticks uses an input vector to define where the ticks are located on the x-axis.

errorbar(1:4,quadrantMean,quadrantSpread)
xticks(1:4)
xlim([0.8 4.2])
xlabel("Quadrant")
ylabel("Mean Temperature (°C)")
title("Mean Temperature Values Across Quadrants")

We see from this plot that the temperatures in quadrant 4 are the most consistent within the desired range of
260 - 290 °C. The other three quadrants all have temperatures that extend well below 260 °C. Also, quadrant 4's
SD is the smallest, so it would likely produce the most even cooking. We should be careful not to burn pizzas in
this quadrant, though, since it's the hottest region.

Quadrants 2 and 3 are likely still appropriate for cooking pizzas since most of their values are above 260 °C,
but the pizzas will take longer to cook than in quadrant 4. Quadrant 1 has the lowest temperatures, so pizzas
cooked in this quadrant will take the longest to cook. Also, the SD values are larger in quadrants 1-3, so we may
need to be careful about rotating the pizzas while cooking to ensure they cooks evenly.

We've now answered our question about which quadrants are the best for cooking pizzas. We answered the
question by calculating descriptive statistics with the matrix of oven temperatures. Besides the mean and std
functions, there are many other basic statistics functions. Some examples are min, mode, and median. Check
this documentation page to learn more about what you can do with the descriptive statistics functions.

Copyright 2021 The MathWorks, Inc.

You might also like