When talking about arrays and data storage, I can’t help but mention some useful statistical functions built into MATLAB. The ones we will talk about are:
The minimum, or min(), function allows the user to find the smallest value within a data set. Let’s see an example of this.
matlab
scores = [78 99 37 56 88 89 95 92 79 68 94 83];
min(scores); % output: 37
The maximum, or max(), function searches through a data set and finds the largest value in the data.
matlab
% From before
scores = [78 99 37 56 88 89 95 92 79 68 94 83];
max(scores); % output 99
The average, or mean(), computes the average of the data set. This is quantified as the sum of the data points divided by the number of data points. Either method works for finding the mean.
matlab
% From before
scores = [78 99 37 56 88 89 95 92 79 68 94 83];
mean(scores); % output: 79.8333
The standard deviation, or std(), calculates the standard deviation of the data set. Let’s see how it works.
matlab
% From before
scores = [78 99 37 56 88 89 95 92 79 68 94 83];
std(scores); % output: 18.2250
The sum() function adds up all of the data values in a data set.
matlab
% From before
scores = [78 99 37 56 88 89 95 92 79 68 94 83];
sum(scores); % output: 958