

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


A = [ 2, 4, 2, 3, 5, 1, 4, 3] and B = [1, 2, 2, 1, 5, 4, 1, 3] and C = [NaN, 2, NaN, 3] are three MATLAB variables representing sets of measurements used in the examples below. Let D be a MATLAB matrix
that we will use in our formulas.
1. The average or mean measures the central tendency of a set of numbers. To calculate the average,
=
n k 1
Example 1: The average of A is (2 + 4 + 2 + 3 + 5 + 1 + 4 + 3)/8 = 3 The MATLAB function for average is called mean. Example 2: mean(D, 1) or mean(D) is the column mean of D. It is a single row of 3 values. Example 3: mean(D, 2) is the row mean of D. It is a single column of 4 values. Example 4: mean(A) is the mean of A. (For vectors, you never need the second parameter and the result is always a single number.) Example 5: The mean of the entire array D is mean(D(:)). Here we use the linear representation of D to extract a single value. Example 6: mean(C) is NaN. The MATLAB returns NaN results if any of the values in the vector are NaN. The MATLAB function nanmean computes the average by completely ignoring the NaNs.
2. The median is another measure of central tendency. In contrast to the average, the median is not heavily influenced by outliers. When the average and the median are far apart in value, you can surmise that there must be some outliers in the data. To calculate the median, sort the values and take the middle one. If the number of items is even, average the middle two values. Example 7: sort(A) is [ 1, 2, 2, 2, 3, 3, 4, 5]. The average of the middle two values is (2 + 3)/2 = 2. The MATLAB function for computing the median is called median. The median function follows the same rules as the mean function. The MATLAB function nanmedian computes the median by completely ignoring the NaNs. 3. The mode is the value most frequently appearing in the data. This value may not be unique. Example 8: The mode of B is 1, while the mode of A has two most frequent values: 2 and 4
4. The standard deviation measures the spread or dispersion of values from the mean. The standard deviation is calculated as the square root of the average of the squares of the distance of each value
n^2 k 1
=
Example 9: Calculate the standard deviation of A: a) First compute the sum of the squares of the differences with the mean (2 ‐ 3)^2 + (4 ‐ 3)^2 + (2 ‐ 3)^2 + (3 ‐ 3) 2 + (5 ‐ 3)^2 + (1 ‐ 3)^2 + (4 ‐ 3) 2 + (3 ‐ 3)^2 = 1 + 1 + 1 + 0 + 4 + 4 + 1 + 0 = 12
The MATLAB function for computing the standard deviation is called std. Example 10: std(D, 1, 1) is the standard deviation of the columns of D. It is a row vector of size 1 x
Example 11: std(D) contains a row vector with an unbiased estimator of the population standard deviation. This could also be written as std(D, 0, 1). (The populations and samples handout.) Example 12: std(D, 1, 2) is the standard deviation of the rows of D. It is a column vector of size 4 x
The MATLAB function nanstd computes the standard deviation by completely ignoring the NaNs. The nanstd function follows the same rules as the std.
5. The pth^ percentile is the data value such that p% of the data fall below that value. The 50% percentile is the median. The 25 th^ percentile is sometimes called the first quartile. Example 13: MATLAB statement [a, b] = prctile(x, [25, 75]); has the 25 th^ percentile value in a and the 75 th^ percentile value in b. 6. Boxplots use the 75th percentile for the top of the box and the 25th percentile for the bottom of the box. The horizontal line across the box corresponds to the median value. Example 14: The MATLAB statement boxplot(x) produces a boxplot showing the distribution of values in the vector x. 7. The interquartile range (IQR) is the 75 th^ percentile minus the 25 th^ percentile.