Session 6: Statistics
Objectives
In this session, we will learn the following:
- Scilab functions to obtain basic statistics of the elements of a matrix
Scilab Functions for Statistics
Scilab provides the following functions for computing simple statistics of matrices:
- sum() - sum of array elements
- mean() - mean of array elements
- median() - median of array elements
- st_deviation() or stdev() - standard deviation of array elements
- stdevf() - standard deviation of array elements using frequencies
- nanstdev() - standard deviatin ignoring NaN (not a number) values
Each of these functions can be used in one of hree ways:
- To calculate the statistical quantity for all elements of the array. x = sum(a) computes the sum of all elements of matrix a and assigns it to x.
- y = sum(a, 'r') or y = sum(a, 1) return a row vector wherein the number in each column is the sum of the elements of the respective column of matrix a. Thus, y is a row vector having the same number of columns as matrix a.
- z = sum(a, 'c') or z = sum(a, 2) return a column vector wherein the number in each row is the sum of the elements of the respective row of matrix a. Thus, z is a column vector having the same number of of rows as matrix a.
Other functions can be used in the same way as the function sum(). Let us try out an example:
-->a = [73 24 89 94; 20 24 66 22; 55 22 31 32];
-->sum(a)
ans =
552.
-->sum(a, 'r')
ans =
148. 70. 186. 148.
-->sum(a, 'c')
ans =
280.
132.
140.
-->sum(a, 1)
ans =
148. 70. 186. 148.
-->sum(a, 2)
ans =
280.
132.
140.