Example Inbuilt Functions Using Scalars, Vectors and Matrices (Part 2)

Tutorial Video

Inbuilt Functions with Multiple Input Forms

Previously we looked at some functions which could be used on Scalar, Vector or Matrix Inputs. If a Scalar Input was selected then a Scalar Output was selected. If a Vector or Matrix input was selected then a corresponding Vector or Matrix output was created with the function acting on the input Matrix, element by element.

Some other functions however act differently depending on the presence of absence of additional inputs.

max function

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">max(</span>M<span style="color: #808080;">,</span>N<span style="color: #808080;">,</span>direction<span style="color: #0000ff;">)</span>

Let's create two different Matrices of equal dimensions:

M=<span style="color: #ff0000;">[</span>1<span style="color: #808080;">,</span>4<span style="color: #808080;">,</span>5<span style="color: #ff00ff;">;</span>7<span style="color: #808080;">,</span>10<span style="color: #808080;">,</span>11<span style="color: #ff00ff;">;</span>13<span style="color: #808080;">,</span>15<span style="color: #808080;">,</span>18<span style="color: #ff0000;">]</span>
N=<span style="color: #ff0000;">[</span>2<span style="color: #808080;">,</span>3<span style="color: #808080;">,</span>6<span style="color: #ff00ff;">;</span>8<span style="color: #808080;">,</span>9<span style="color: #808080;">,</span>12<span style="color: #ff00ff;">;</span>14<span style="color: #808080;">,</span>16<span style="color: #808080;">,</span>17<span style="color: #ff0000;">]</span>

\displaystyle \text{M}=\left[ {\begin{array}{*{20}{c}} 1 & {\mathbf{4}} & 5 \\ 7 & {\mathbf{10}} & {11} \\ {13} & {15} & {\mathbf{18}} \end{array}} \right]

\displaystyle \text{N}=\left[ {\begin{array}{*{20}{c}} {\mathbf{2}} & 3 & {\mathbf{6}} \\ {\mathbf{8}} & 9 & {\mathbf{12}} \\ {\mathbf{14}} & {\mathbf{16}} & {17} \end{array}} \right]

We can use the function:

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">max(</span>M<span style="color: #808080;">,</span>N<span style="color: #0000ff;">)</span>

To get the maximum value of each element between the two Matrices.

\displaystyle \text{max(M,N)=}\left[ {\begin{array}{*{20}{c}} {\text{max(1,}}{\mathbf{2)}} & {\text{max(}}{\mathbf{4}}{\text{,3)}} & {\text{max(5,}}{\mathbf{6)}} \\ {\text{max(7,}}{\mathbf{8)}} & {\text{max(}}{\mathbf{10}}{\text{,9)}} & {\text{max(11,}}{\mathbf{12)}} \\ {\text{max(13,}}{\mathbf{14)}} & {\text{max(15,}}{\mathbf{16)}} & {\text{max(}}{\mathbf{18}}{\text{,17)}} \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} 2 & 4 & 6 \\ 8 & {10} & {12} \\ {14} & {16} & {18} \end{array}} \right]

As seen for the 1st Row and 1st Column, the value of N is higher than that of M so it is taken for the output Matrix while the value in the 1st Row and 2nd Column is higher in M than N do is taken for the Output Matrix and so on and so forth:

Using only 1 input matrix, skipping the second input matrix using

<span style="color: #ff6600;">[</span> <span style="color: #ff6600;">]</span>

and specifying the Direction as 1 instead finds the Maximum in each Column:

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">max(</span>M<span style="color: #808080;">,</span><span style="color: #ff6600;">[]</span><span style="color: #808080;">,</span>1<span style="color: #0000ff;">)</span>

\displaystyle \max \left( {\text{M,}\left[ {} \right]\text{,1}} \right)=\left[ {\begin{array}{*{20}{c}} {\max \left( {\left[ {\begin{array}{*{20}{c}} 1 \\ 7 \\ {\mathbf{13}} \end{array}} \right]} \right)} & {\max \left( {\left[ {\begin{array}{*{20}{c}} 4 \\ {10} \\ {\mathbf{15}} \end{array}} \right]} \right)} & {\max \left( {\left[ {\begin{array}{*{20}{c}} 5 \\ {11} \\ {\mathbf{18}} \end{array}} \right]} \right)} \end{array}} \right]

This results in a Row Vector of maximum values in each Column:

\displaystyle \max \left( {\text{M,}\left[ {} \right]\text{,1}} \right)=\left[ {\begin{array}{*{20}{c}} {13} & {15} & {18} \end{array}} \right]

The max function also works this way with only 1 input matrix giving the same result as above:

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">max(</span>M<span style="color: #0000ff;">)</span>

\displaystyle \max \left( \text{M} \right)=\left[ {\begin{array}{*{20}{c}} {\max \left( {\left[ {\begin{array}{*{20}{c}} 1 \\ 7 \\ {\mathbf{13}} \end{array}} \right]} \right)} & {\max \left( {\left[ {\begin{array}{*{20}{c}} 4 \\ {10} \\ {\mathbf{15}} \end{array}} \right]} \right)} & {\max \left( {\left[ {\begin{array}{*{20}{c}} 5 \\ {11} \\ {\mathbf{18}} \end{array}} \right]} \right)} \end{array}} \right]

\displaystyle \max \left( \text{M} \right)=\left[ {\begin{array}{*{20}{c}} {13} & {15} & {18} \end{array}} \right]

Using only 1 input matrix, skipping the second input matrix using

<span style="color: #ff6600;">[</span> <span style="color: #ff6600;">]</span>

and specifying the Direction as 2 instead finds the Maximum in each Row:

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">max(</span>M<span style="color: #808080;">,</span><span style="color: #ff6600;">[]</span><span style="color: #808080;">,</span>2<span style="color: #0000ff;">)</span>

\displaystyle \max \left( {\text{M,}\left[ {} \right]\text{,2}} \right)=\left[ {\begin{array}{*{20}{c}} {\max \left( {\left[ {\begin{array}{*{20}{c}} 1 & 4 & {\mathbf{5}} \end{array}} \right]} \right)} \\ {\max \left( {\left[ {\begin{array}{*{20}{c}} 7 & {10} & {\mathbf{11}} \end{array}} \right]} \right)} \\ {\max \left( {\left[ {\begin{array}{*{20}{c}} {13} & {15} & {\mathbf{18}} \end{array}} \right]} \right)} \end{array}} \right]

\displaystyle \max \left( {\text{M,}\left[ {} \right]\text{,2}} \right)=\left[ {\begin{array}{*{20}{c}} 5 \\ {11} \\ {18} \end{array}} \right]

Using only 1 input matrix, skipping the second input matrix using

<span style="color: #ff6600;">[</span> <span style="color: #ff6600;">]</span>

and specifying the direction as

<span style="color: #800080;">'</span>all<span style="color: #800080;">'</span>

will instead find the single Maximum Value of all the elements in the Matrix outputting a Scalar. Note

<span style="color: #800080;">'</span>all<span style="color: #800080;">'</span>

is a text input and has to be enclosed in

<span style="color: #800080;">'</span> <span style="color: #800080;">'</span>

.

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">max(</span>M<span style="color: #808080;">,</span><span style="color: #ff6600;">[]</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span>all<span style="color: #800080;">'</span><span style="color: #0000ff;">)</span>
<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">max(</span><span style="color: #33cccc;">M(</span>:<span style="color: #33cccc;">)</span><span style="color: #0000ff;">)</span>

\displaystyle \text{max(M,}\left[ {} \right],'\text{all}'\text{)=max(M(:))}=\text{max}\left( {\left[ {\begin{array}{*{20}{c}} 1 \\ 7 \\ {13} \\ 4 \\ {10} \\ {15} \\ 5 \\ {11} \\ {\mathbf{18}} \end{array}} \right]} \right)=18

Recall we can type in:

<span style="color: #0000ff;">max(</span>

To view the multiple input forms this function accepts. We can select More Help… if we require more information.

min function

The function

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">min(</span>M<span style="color: #808080;">,</span>N<span style="color: #808080;">,</span>direction<span style="color: #0000ff;">)</span>

Unsurprisingly has an identical form to the

max

function used above. We can once again compare

M

and

N
M=<span style="color: #ff0000;">[</span>1<span style="color: #808080;">,</span>4<span style="color: #808080;">,</span>5<span style="color: #ff00ff;">;</span>7<span style="color: #808080;">,</span>10<span style="color: #808080;">,</span>11<span style="color: #ff00ff;">;</span>13<span style="color: #808080;">,</span>15<span style="color: #808080;">,</span>18<span style="color: #ff0000;">]</span>
N=<span style="color: #ff0000;">[</span>2<span style="color: #808080;">,</span>3<span style="color: #808080;">,</span>6<span style="color: #ff00ff;">;</span>8<span style="color: #808080;">,</span>9<span style="color: #808080;">,</span>12<span style="color: #ff00ff;">;</span>14<span style="color: #808080;">,</span>16<span style="color: #808080;">,</span>17<span style="color: #ff0000;">]</span>

We go element by element and take the minimum value between the two matrices

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">min(</span>M<span style="color: #808080;">,</span>N<span style="color: #0000ff;">)</span>

\displaystyle \text{M}=\left[ {\begin{array}{*{20}{c}} {\mathbf{1}} & {4} & {\mathbf{5}} \\ {\mathbf{7}} & {10} & {\mathbf{11}} \\ {\mathbf{13}} & {\mathbf{15}} & {18} \end{array}} \right]

\displaystyle \text{N}=\left[ {\begin{array}{*{20}{c}} 2 & {\mathbf{3}} & {6} \\ {8} & {\mathbf{9}} & {12} \\ {14} & {16} & {\mathbf{17}} \end{array}} \right]

\displaystyle \text{min(M,N)=}\left[ {\begin{array}{*{20}{c}} {\text{min(}}{\mathbf{1}}{\text{,2)}} & {\text{min(4,}}{\mathbf{3}}{\text{)}} & {\text{min(}}{\mathbf{5}}{\text{,6)}} \\ {\text{min(}}{\mathbf{7}}{\text{,8)}} & {\text{min(10,}}{\mathbf{9}}{\text{)}} & {\text{min(}}{\mathbf{11}}{\text{,12)}} \\ {\text{min(}}{\mathbf{13}}{\text{,14)}} & {\text{min(}}{\mathbf{15}}{\text{,16)}} & {\text{min(18}}{\mathbf{,17}}{\text{)}} \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} 1 & 3 & 5 \\ 7 & 9 & {11} \\ {13} & {15} & {17} \end{array}} \right]

Using only 1 input matrix, skipping the second input matrix using

<span style="color: #ff6600;">[ ]</span>

and specifying the direction as 1 (Direction 1 finds the Minimum in each Column)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">min(</span>M<span style="color: #808080;">,</span><span style="color: #ff6600;">[]</span><span style="color: #808080;">,</span>1<span style="color: #0000ff;">)</span>

\displaystyle \min \left( {\text{M,}\left[ {} \right]\text{,1}} \right)=\left[ {\begin{array}{*{20}{c}} {\min \left( {\left[ {\begin{array}{*{20}{c}} {\mathbf{1}} \\ 7 \\ {13} \end{array}} \right]} \right)} & {\min \left( {\left[ {\begin{array}{*{20}{c}} {\mathbf{4}} \\ {10} \\ {15} \end{array}} \right]} \right)} & {\min \left( {\left[ {\begin{array}{*{20}{c}} {\mathbf{5}} \\ {11} \\ {18} \end{array}} \right]} \right)} \end{array}} \right]

\displaystyle \min \left( {\text{M,}\left[ {} \right]\text{,1}} \right)=\left[ {\begin{array}{*{20}{c}} 1 & 4 & 5 \end{array}} \right]

The min function also works this way with only 1 input matrix:

\displaystyle \min \left( \text{M} \right)=\left[ {\begin{array}{*{20}{c}} 1 & 4 & 5 \end{array}} \right]

Using only 1 input matrix, skipping the second input matrix using

[ ]

and specifying the direction as 2 (Direction 2 finds the Minimum in each Row)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">min(</span>M<span style="color: #808080;">,</span><span style="color: #ff6600;">[]</span><span style="color: #808080;">,</span>2<span style="color: #0000ff;">)</span>

\displaystyle \min \left( {\text{M,}\left[ {} \right]\text{,2}} \right)=\left[ {\begin{array}{*{20}{c}} {\min \left( {\left[ {\begin{array}{*{20}{c}} {\mathbf{1}} & 4 & 5 \end{array}} \right]} \right)} \\ {\min \left( {\left[ {\begin{array}{*{20}{c}} {\mathbf{7}} & {10} & {11} \end{array}} \right]} \right)} \\ {\min \left( {\left[ {\begin{array}{*{20}{c}} {\mathbf{13}} & {15} & {18} \end{array}} \right]} \right)} \end{array}} \right]

\displaystyle \min \left( {\text{M,}\left[ {} \right]\text{,2}} \right)=\left[ {\begin{array}{*{20}{c}} 1 \\ 7 \\ {13} \end{array}} \right]

Using only 1 input matrix, skipping the second input matrix using

<span style="color: #ff6600;">[</span> <span style="color: #ff6600;">]</span>

and specifying the direction as all (Direction all finds the Minimum in the entire Matrix)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">min(</span>M<span style="color: #808080;">,</span><span style="color: #ff6600;">[]</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span>all<span style="color: #800080;">'</span><span style="color: #0000ff;">)</span>
<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">min(</span><span style="color: #008080;">M(</span>:<span style="color: #008080;">)</span><span style="color: #0000ff;">)</span>

\displaystyle \text{min(M,}\left[ {} \right],'\text{all}'\text{)=min(M(:))}=\text{min}\left( {\left[ {\begin{array}{*{20}{c}} 1 \\ 7 \\ {13} \\ 4 \\ {10} \\ {15} \\ 5 \\ {11} \\ {18} \end{array}} \right]} \right)=1

sum function

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">sum(</span>M<span style="color: #808080;">,</span>direction<span style="color: #0000ff;">)</span>

M=<span style="color: #ff0000;">[</span>1<span style="color: #808080;">,</span>2<span style="color: #808080;">,</span>3<span style="color: #ff00ff;">;</span>4<span style="color: #808080;">,</span>5<span style="color: #808080;">,</span>6<span style="color: #ff00ff;">;</span>7<span style="color: #808080;">,</span>8<span style="color: #808080;">,</span>9<span style="color: #ff0000;">]</span>

\displaystyle \text{M}=\left[ {\begin{array}{*{20}{c}} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{array}} \right]

Inputting the input matrix M and specifying the Direction as 1 (Direction 1 finds the Sum of elements in each Column)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">sum(</span>M<span style="color: #808080;">,</span>1<span style="color: #0000ff;">)</span>

\displaystyle \text{sum(M,1)}=\left[ {\begin{array}{*{20}{c}} {\text{sum}\left( {\left[ {\begin{array}{*{20}{c}} 1 \\ 4 \\ 7 \end{array}} \right]} \right)} & {\text{sum}\left( {\left[ {\begin{array}{*{20}{c}} 2 \\ 5 \\ 8 \end{array}} \right]} \right)} & {\text{sum}\left( {\left[ {\begin{array}{*{20}{c}} 3 \\ 6 \\ 9 \end{array}} \right]} \right)} \end{array}} \right]

\displaystyle \text{sum(M,1)}=\left[ {\begin{array}{*{20}{c}} {1+4+7} & {2+5+8} & {3+6+9} \end{array}} \right]

\displaystyle \text{sum(M,1)}=\left[ {\begin{array}{*{20}{c}} {12} & {15} & {18} \end{array}} \right]

Inputting the input matrix M and specifying the Direction as 2 (Direction 2 finds the Sum of elements in each Row)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">sum(</span>M<span style="color: #808080;">,</span>2<span style="color: #0000ff;">)</span>

\displaystyle \text{sum(M,2)}=\left[ {\begin{array}{*{20}{c}} {\text{sum}\left( {\left[ {\begin{array}{*{20}{c}} 1 & 2 & 3 \end{array}} \right]} \right)} \\ {\text{sum}\left( {\left[ {\begin{array}{*{20}{c}} 4 & 5 & 6 \end{array}} \right]} \right)} \\ {\text{sum}\left( {\left[ {\begin{array}{*{20}{c}} 7 & 8 & 9 \end{array}} \right]} \right)} \end{array}} \right]

\displaystyle \text{sum(M,2)}=\left[ {\begin{array}{*{20}{c}} {1+2+3} \\ {4+5+6} \\ {7+8+9} \end{array}} \right]

\displaystyle \text{sum(M,2)}=\left[ {\begin{array}{*{20}{c}} 6 \\ {15} \\ {24} \end{array}} \right]

Using only 1 input matrix, and specifying the direction as all (Direction all finds the Sum of all elements in the entire Matrix)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">sum(</span>M<span style="color: #808080;">,</span><span style="color: #800080;">'</span>all<span style="color: #800080;">'</span><span style="color: #0000ff;">)</span>=<span style="color: #0000ff;">sum(</span><span style="color: #008080;">M(</span>:<span style="color: #008080;">)</span><span style="color: #0000ff;">)</span>

\displaystyle \text{sum(M,}'\text{all}'\text{)=sum(M(:))}=\text{sum}\left( {\left[ {\begin{array}{*{20}{c}} 1 \\ 4 \\ 7 \\ 2 \\ 5 \\ 8 \\ 3 \\ 6 \\ 9 \end{array}} \right]} \right)=45

We can type in

<span style="color: #0000ff;">sum(</span>

to get information about the inputs:

prod function

The function

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">prod(</span>M<span style="color: #808080;">,</span>direction<span style="color: #0000ff;">)</span>

has a similar form to the

sum

function except it calculates the sum of the product opposed to the sum.

M=<span style="color: #ff0000;">[</span>1<span style="color: #808080;">,</span>2<span style="color: #808080;">,</span>3<span style="color: #ff00ff;">;</span>4<span style="color: #808080;">,</span>5<span style="color: #808080;">,</span>6<span style="color: #ff00ff;">;</span>7<span style="color: #808080;">,</span>8<span style="color: #808080;">,</span>9<span style="color: #ff0000;">]</span>

\displaystyle \text{M}=\left[ {\begin{array}{*{20}{c}} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{array}} \right]

Inputting the input matrix M and specifying the Direction as 1 (Direction 1 finds the Product of all elements for each Column)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">prod(</span>M<span style="color: #808080;">,</span>1<span style="color: #0000ff;">)</span>

\displaystyle \text{prod(M,1)}=\left[ {\begin{array}{*{20}{c}} {\text{prod}\left( {\left[ {\begin{array}{*{20}{c}} 1 \\ 4 \\ 7 \end{array}} \right]} \right)} & {\text{prod}\left( {\left[ {\begin{array}{*{20}{c}} 2 \\ 5 \\ 8 \end{array}} \right]} \right)} & {\text{prod}\left( {\left[ {\begin{array}{*{20}{c}} 3 \\ 6 \\ 9 \end{array}} \right]} \right)} \end{array}} \right]

\displaystyle \text{prod(M,1)}=\left[ {\begin{array}{*{20}{c}} {1*4*7} & {2*5*8} & {3*6*9} \end{array}} \right]

\displaystyle \text{prod(M,1)}=\left[ {\begin{array}{*{20}{c}} {28} & {80} & {162} \end{array}} \right]

Inputting the input matrix M and specifying the Direction as 2 (Direction 2 finds the Product of elements in each Row)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">prod(</span>M<span style="color: #808080;">,</span>2<span style="color: #0000ff;">)</span>

\displaystyle \text{prod(M,2)}=\left[ {\begin{array}{*{20}{c}} {\text{prod}\left( {\left[ {\begin{array}{*{20}{c}} 1 & 2 & 3 \end{array}} \right]} \right)} \\ {\text{prod}\left( {\left[ {\begin{array}{*{20}{c}} 4 & 5 & 6 \end{array}} \right]} \right)} \\ {\text{prod}\left( {\left[ {\begin{array}{*{20}{c}} 7 & 8 & 9 \end{array}} \right]} \right)} \end{array}} \right]

\displaystyle \text{prod(M,2)}=\left[ {\begin{array}{*{20}{c}} {1*2*3} \\ {4*5*6} \\ {7*8*9} \end{array}} \right]

\displaystyle \text{prod(M,2)}=\left[ {\begin{array}{*{20}{c}} 6 \\ {120} \\ {504} \end{array}} \right]

Using only 1 input matrix, and specifying the direction as all (Direction all finds the Product of all elements in the entire Matrix)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">prod(</span>M<span style="color: #808080;">,</span><span style="color: #800080;">'</span>all<span style="color: #800080;">'</span><span style="color: #0000ff;">)</span>=<span style="color: #0000ff;">prod(</span><span style="color: #008080;">M(</span>:<span style="color: #008080;">)</span><span style="color: #0000ff;">)</span>

\displaystyle \text{prod(M,}'\text{all}'\text{)=prod(M(:))}=\text{prod}\left( {\left[ {\begin{array}{*{20}{c}} 1 \\ 4 \\ 7 \\ 2 \\ 5 \\ 8 \\ 3 \\ 6 \\ 9 \end{array}} \right]} \right)=362880

mean function

\displaystyle {{\mu }_{x}}=\text{mean}=\sum\nolimits_{{i=1}}^{m}{{{{x}_{i}}}}

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">mean(</span>M<span style="color: #808080;">,</span>direction<span style="color: #0000ff;">)</span>
M=<span style="color: #ff0000;">[</span>1<span style="color: #808080;">,</span>2<span style="color: #808080;">,</span>3<span style="color: #ff00ff;">;</span>4<span style="color: #808080;">,</span>5<span style="color: #808080;">,</span>6<span style="color: #ff00ff;">;</span>7<span style="color: #808080;">,</span>8<span style="color: #808080;">,</span>9<span style="color: #ff0000;">]</span>

\displaystyle \text{M}=\left[ {\begin{array}{*{20}{c}} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{array}} \right]

Inputting the input matrix M and specifying the direction as 1 (Direction 1 finds the Mean in each Column)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">mean(</span>M<span style="color: #808080;">,</span>1<span style="color: #0000ff;">)</span>

\displaystyle \text{mean}\left( {\text{M},1} \right)=\left[ {\begin{array}{*{20}{c}} {\text{mean}\left( {\begin{array}{*{20}{c}} 1 \\ 4 \\ 7 \end{array}} \right)} & {\text{mean}\left( {\begin{array}{*{20}{c}} 2 \\ 5 \\ 8 \end{array}} \right)} & {\text{mean}\left( {\begin{array}{*{20}{c}} 3 \\ 6 \\ 9 \end{array}} \right)} \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} 4 & 5 & 6 \end{array}} \right]

Inputting the input matrix M and specifying the direction as 2 (Direction 2 finds the Mean in each Row)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">mean(</span>M<span style="color: #808080;">,</span>2<span style="color: #0000ff;">)</span>

\displaystyle \text{mean(M},2\text{)}=\left[ {\begin{array}{*{20}{c}} {\text{mean}\left( {\begin{array}{*{20}{c}} 1 & 2 & 3 \end{array}} \right)} \\ {\text{mean}\left( {\begin{array}{*{20}{c}} 4 & 5 & 6 \end{array}} \right)} \\ {\text{mean}\left( {\begin{array}{*{20}{c}} 7 & 8 & 9 \end{array}} \right)} \end{array}} \right]=\left[ {\begin{array}{*{20}{c}} 2 \\ 5 \\ 8 \end{array}} \right]

Using only 1 input matrix, and specifying the direction as all (Direction all finds the Mean of the entire Matrix)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">mean(</span>M<span style="color: #808080;">,</span><span style="color: #800080;">'</span>all<span style="color: #800080;">'</span><span style="color: #0000ff;">)</span>=<span style="color: #0000ff;">mean(</span><span style="color: #008080;">M(</span>:<span style="color: #008080;">)</span><span style="color: #0000ff;">)</span>

\displaystyle \text{mean(M,}'\text{all}'\text{)=mean(M(:))}=\text{mean}\left( {\left[ {\begin{array}{*{20}{c}} 1 \\ 4 \\ 7 \\ 2 \\ 5 \\ 8 \\ 3 \\ 6 \\ 9 \end{array}} \right]} \right)=5

median function

The median finds the middle number in each Column or Row.

<span style="color: #0000ff;">median(</span>M<span style="color: #808080;">,</span>direction<span style="color: #0000ff;">)</span>
M=<span style="color: #ff0000;">[</span>7<span style="color: #808080;">,</span>1<span style="color: #808080;">,</span>4<span style="color: #808080;">,</span>3<span style="color: #ff00ff;">;</span>2<span style="color: #808080;">,</span>9<span style="color: #808080;">,</span>100<span style="color: #808080;">,</span>8<span style="color: #ff00ff;">;</span>10<span style="color: #808080;">,</span>5<span style="color: #808080;">,</span>6<span style="color: #808080;">,</span>11<span style="color: #ff0000;">]</span>

\displaystyle \text{M}=\left[ {\begin{array}{*{20}{c}} 7 & 1 & 4 & 3 \\ 2 & 9 & {100} & 8 \\ {10} & 5 & 6 & {11} \end{array}} \right]

Inputting the input matrix M and specifying the Direction as 1 (Direction 1 finds the Median in each Column)

<span style="color: #ff0000;">[</span>output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">median(</span>M<span style="color: #808080;">,</span>1<span style="color: #0000ff;">)</span>

\displaystyle \text{median}\left( {\text{M,1}} \right)=

\displaystyle \left[ {\begin{array}{*{20}{c}} {\text{median}\left( {\left[ {\begin{array}{*{20}{c}} 7 \\ 2 \\ {10} \end{array}} \right]} \right)} & {\text{median}\left( {\left[ {\begin{array}{*{20}{c}} 1 \\ 9 \\ 5 \end{array}} \right]} \right)} & {\text{median}\left( {\left[ {\begin{array}{*{20}{c}} 4 \\ {100} \\ 6 \end{array}} \right]} \right)} & {\text{median}\left( {\left[ {\begin{array}{*{20}{c}} 3 \\ 8 \\ {11} \end{array}} \right]} \right)} \end{array}} \right]

\displaystyle \text{median}\left( {\text{M,1}} \right)=\left[ {\begin{array}{*{20}{c}} 7 & 5 & 6 & 8 \end{array}} \right]

<span style="color: #ff0000;">[</span>output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">median(</span>M<span style="color: #0000ff;">)</span>

\displaystyle \text{median}\left( \text{M} \right)=\left[ {\begin{array}{*{20}{c}} 7 & 5 & 6 & 8 \end{array}} \right]

In this small dataset there is a large outlier:

\displaystyle \text{M}=\left[ {\begin{array}{*{20}{c}} 7 & 1 & 4 & 3 \\ 2 & 9 & {\mathbf{100}} & 8 \\ {10} & 5 & 6 & {11} \end{array}} \right]

If we use the mean, it is highly influenced by this outlier and in this case, the median is more representative of the dataset:

\displaystyle \text{mean}\left( {\text{M,1}} \right)=\left[ {\begin{array}{*{20}{c}} {6.3333} & {5.0000} & {36.6667} & {7.3333} \end{array}} \right]

Inputting the input matrix M and specifying the Direction as 2 (Direction 2 finds the Median in each Row)

<span style="color: #ff0000;">[</span>output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">median(</span>M<span style="color: #ff0000;">,</span>2<span style="color: #0000ff;">)</span>

\displaystyle \text{median}\left( {\text{M,2}} \right)=\left[ {\begin{array}{*{20}{c}} {\text{median}\left( {\left[ {\begin{array}{*{20}{c}} 7 & 1 & 4 & 3 \end{array}} \right]} \right)} \\ {\text{median}\left( {\left[ {\begin{array}{*{20}{c}} 2 & 9 & {100} & 8 \end{array}} \right]} \right)} \\ {\text{median}\left( {\left[ {\begin{array}{*{20}{c}} {10} & 5 & 6 & {11} \end{array}} \right]} \right)} \end{array}} \right]

\displaystyle \text{median}\left( {\text{M,2}} \right)=\left[ {\begin{array}{*{20}{c}} {3.5} \\ {8.5} \\ 8 \end{array}} \right]

If we compare this again with the mean, it is highly influenced by the outlier and once again the median is more representative of the dataset:

\displaystyle \text{mean}\left( {\text{M,2}} \right)=\left[ {\begin{array}{*{20}{c}} {3.75} \\ {29.75} \\ 8 \end{array}} \right]

Using only 1 input matrix, and specifying the direction as all (Direction all finds the Median of the entire Matrix)

<span style="color: #ff0000;">[</span>output<span style="color: #ff0000;">]<span style="color: #000000;">=</span><span style="color: #0000ff;">median(</span><span style="color: #000000;">M<span style="color: #808080;">,</span><span style="color: #800080;">'</span>all<span style="color: #800080;">'</span></span><span style="color: #0000ff;">)</span></span>=<span style="color: #0000ff;">median(</span><span style="color: #008080;">M</span><span style="color: #808080;"><span style="color: #008080;">(</span>:<span style="color: #008080;">)</span></span><span style="color: #0000ff;">)</span>

\displaystyle \text{median(M, }\!\!'\!\!\text{ all }\!\!'\!\!\text{ )}=\text{median(M(:))}=\text{median}\left( {\left[ {\begin{array}{*{20}{c}} 7 \\ 2 \\ {10} \\ 1 \\ 9 \\ 5 \\ 4 \\ {100} \\ 6 \\ 3 \\ 8 \\ {11} \end{array}} \right]} \right)=6.5

mode function

The mode finds the number that occurs the most.

<span style="color: #ff0000;">[</span>output<span style="color: #ff0000;">]<span style="color: #000000;">=</span></span><span style="color: #0000ff;">mode(</span>M<span style="color: #808080;">,</span>direction<span style="color: #0000ff;">)</span>

\displaystyle \text{M}=\left[ {\begin{array}{*{20}{c}} 1 & 2 & 9 & 9 \\ 1 & 9 & {14} & 9 \\ {11} & 9 & {14} & {14} \end{array}} \right]

Inputting the input matrix M and specifying the Direction as 1 (Direction 1 finds the Mode Value in each Column)

<span style="color: #ff0000;">[</span>output<span style="color: #ff0000;">]<span style="color: #000000;">=</span></span><span style="color: #0000ff;">mode(</span>M<span style="color: #808080;">,</span>1<span style="color: #0000ff;">)</span>

\displaystyle \text{mode(M,1)=}\left[ {\begin{array}{*{20}{c}} {\text{mode}\left( {\left[ {\begin{array}{*{20}{c}} {\mathbf{1}} \\ {\mathbf{1}} \\ {11} \end{array}} \right]} \right)} & {\text{mode}\left( {\left[ {\begin{array}{*{20}{c}} 2 \\ {\mathbf{9}} \\ {\mathbf{9}} \end{array}} \right]} \right)} & {\text{mode}\left( {\left[ {\begin{array}{*{20}{c}} 9 \\ {\mathbf{14}} \\ {\mathbf{14}} \end{array}} \right]} \right)} & {\text{mode}\left( {\left[ {\begin{array}{*{20}{c}} {\mathbf{9}} \\ {\mathbf{9}} \\ {14} \end{array}} \right]} \right)} \end{array}} \right]

\displaystyle \text{mode(M,1)=}\left[ {\begin{array}{*{20}{c}} 1 & 9 & {14} & 9 \end{array}} \right]

\displaystyle \text{mode(M)=}\left[ {\begin{array}{*{20}{c}} 1 & 9 & {14} & 9 \end{array}} \right]

Inputting the input matrix M and specifying the Direction as 2 (Direction 2 finds the Mode Value in each Row)

<span style="color: #ff0000;">[</span>output<span style="color: #ff0000;">]<span style="color: #000000;">=</span></span><span style="color: #0000ff;">mode(</span>M<span style="color: #808080;">,</span>2<span style="color: #0000ff;">)</span>

\displaystyle \text{mode(M,2)=}\left[ {\begin{array}{*{20}{c}} {\text{mode}\left( {\left[ {\begin{array}{*{20}{c}} 1 & 2 & {\mathbf{9}} & {\mathbf{9}} \end{array}} \right]} \right)} \\ {\text{mode}\left( {\left[ {\begin{array}{*{20}{c}} 1 & {\mathbf{9}} & {14} & {\mathbf{9}} \end{array}} \right]} \right)} \\ {\text{mode}\left( {\left[ {\begin{array}{*{20}{c}} {11} & 9 & {\mathbf{14}} & {\mathbf{14}} \end{array}} \right]} \right)} \end{array}} \right]

\displaystyle \text{mode(M,2)=}\left[ {\begin{array}{*{20}{c}} 9 \\ 9 \\ {14} \end{array}} \right]

Using only 1 input matrix, and specifying the direction as all (Direction all finds the Mode of the entire Matrix)

<span style="color: #ff0000;">[</span>output<span style="color: #ff0000;">]<span style="color: #000000;">=</span></span><span style="color: #0000ff;">mode(</span>M<span style="color: #808080;">,</span><span style="color: #800080;">'</span>all<span style="color: #800080;">'</span><span style="color: #0000ff;">)</span>=<span style="color: #0000ff;">mode(</span><span style="color: #008080;">M(</span>:<span style="color: #008080;">)</span><span style="color: #0000ff;">)</span>

\displaystyle \text{mode(M(:))}=\text{mode(M, }\!\!'\!\!\text{ all }\!\!'\!\!\text{ )}=\left[ {\begin{array}{*{20}{c}} 1 \\ 1 \\ {11} \\ 2 \\ {\mathbf{9}} \\ {\mathbf{9}} \\ {\mathbf{9}} \\ {14} \\ {14} \\ {\mathbf{9}} \\ {\mathbf{9}} \\ {14} \end{array}} \right]=9

var function

\displaystyle \text{var=}\frac{{\sum\limits_{{i=1}}^{m}{{{{{\left( {x-{{\mu }_{x}}} \right)}}^{2}}}}}}{{m-1}}=\frac{{\sum\limits_{{i=1}}^{m}{{{{{\left( {x-{{x}_{{\text{mean}}}}} \right)}}^{2}}}}}}{{m-1}}

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">var(</span>M<span style="color: #808080;">,</span>weight<span style="color: #808080;">,</span>direction<span style="color: #0000ff;">)</span>
M=<span style="color: #ff0000;">[</span>1<span style="color: #808080;">,</span>2<span style="color: #808080;">,</span>3<span style="color: #ff00ff;">;</span>4<span style="color: #808080;">,</span>5<span style="color: #808080;">,</span>6<span style="color: #ff00ff;">;</span>7<span style="color: #808080;">,</span>8<span style="color: #808080;">,</span>9<span style="color: #ff0000;">]</span>

\displaystyle \text{M}=\left[ {\begin{array}{*{20}{c}} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{array}} \right]

\displaystyle \text{mean}\left( {\text{M,1}} \right)=\left[ {\begin{array}{*{20}{c}} 4 & 5 & 6 \end{array}} \right]

Using 1 input matrix, skipping the second input, the weight using

<span style="color: #ff6600;">[</span> <span style="color: #ff6600;">]</span>

and specifying the direction as 1 (Direction 1 finds the Variance in each Column)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">var(</span>M<span style="color: #808080;">,</span><span style="color: #ff6600;">[]</span><span style="color: #808080;">,</span>1<span style="color: #0000ff;">)</span>

\displaystyle \text{var}\left( {\text{M,}\left[ {} \right]\text{,1}} \right)=\left[ {\begin{array}{*{20}{c}} {\text{std}\left( {\begin{array}{*{20}{c}} 1 \\ 4 \\ 7 \end{array}} \right)} & {\text{std}\left( {\begin{array}{*{20}{c}} 2 \\ 5 \\ 8 \end{array}} \right)} & {\text{std}\left( {\begin{array}{*{20}{c}} 3 \\ 6 \\ 9 \end{array}} \right)} \end{array}} \right]

\displaystyle \text{var}\left( {\text{M,}\left[ {} \right]\text{,1}} \right)=\left[ {\begin{array}{*{20}{c}} {\frac{{{{{\left( {1-4} \right)}}^{2}}+{{{\left( {4-4} \right)}}^{2}}+{{{\left( {7-4} \right)}}^{2}}}}{{3-1}}} & {\frac{{{{{\left( {2-5} \right)}}^{2}}+{{{\left( {5-5} \right)}}^{2}}+{{{\left( {8-5} \right)}}^{2}}}}{{3-1}}} & {\frac{{{{{\left( {3-6} \right)}}^{2}}+{{{\left( {6-6} \right)}}^{2}}+{{{\left( {9-6} \right)}}^{2}}}}{{3-1}}} \end{array}} \right]

\displaystyle \text{var}\left( {\text{M,}\left[ {} \right]\text{,1}} \right)=\left[ {\begin{array}{*{20}{c}} 9 & 9 & 9 \end{array}} \right]

Using 1 input matrix, skipping the second input, the weight using

<span style="color: #ff6600;">[</span> <span style="color: #ff6600;">]</span>

and specifying the direction as 2 (Direction 2 finds the Variance in each Row)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">var(</span>M<span style="color: #808080;">,</span><span style="color: #ff6600;">[]</span><span style="color: #808080;">,</span>2<span style="color: #0000ff;">)</span>

\displaystyle \text{mean}\left( {\text{M,2}} \right)=\left[ {\begin{array}{*{20}{c}} 2 \\ 5 \\ 8 \end{array}} \right]

\displaystyle \text{var}\left( {\text{M,}\left[ {} \right]\text{,2}} \right)=\left[ {\begin{array}{*{20}{c}} {\text{var}\left( {\begin{array}{*{20}{c}} 1 & 2 & 3 \end{array}} \right)} \\ {\text{var}\left( {\begin{array}{*{20}{c}} 4 & 5 & 6 \end{array}} \right)} \\ {\text{var}\left( {\begin{array}{*{20}{c}} 7 & 8 & 9 \end{array}} \right)} \end{array}} \right]

\displaystyle \text{var}\left( {\text{M,}\left[ {} \right]\text{,2}} \right)=\left[ {\begin{array}{*{20}{c}} {\frac{{{{{(1-2)}}^{2}}+{{{\left( {2-2} \right)}}^{2}}+{{{\left( {3-2} \right)}}^{2}}}}{{3-1}}} \\ {\frac{{{{{(4-5)}}^{2}}+{{{\left( {5-5} \right)}}^{2}}+{{{\left( {6-5} \right)}}^{2}}}}{{3-1}}} \\ {\frac{{{{{(7-8)}}^{2}}+{{{\left( {8-8} \right)}}^{2}}+{{{\left( {9-8} \right)}}^{2}}}}{{3-1}}} \end{array}} \right]

\displaystyle \text{var}\left( {\text{M,}\left[ {} \right]\text{,2}} \right)=\left[ {\begin{array}{*{20}{c}} 1 \\ 1 \\ 1 \end{array}} \right]

Using only 1 input matrix, skipping the second input matrix using

<span style="color: #ff6600;">[</span> <span style="color: #ff6600;">]</span>

and specifying the direction as all (Direction all finds the Variance of the entire Matrix)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">var(</span>M<span style="color: #808080;">,</span><span style="color: #ff6600;">[]</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span>all<span style="color: #800080;">'</span><span style="color: #0000ff;">)</span>

\displaystyle \text{var}\left( {\text{M,}\left[ {} \right],\text{ }\!\!'\!\!\text{ all }\!\!'\!\!\text{ }} \right)=\text{var}\left( {\begin{array}{*{20}{c}} 1 \\ 4 \\ 7 \\ 2 \\ 5 \\ 8 \\ 3 \\ 6 \\ 9 \end{array}} \right)

std Function

\displaystyle \text{std}=\sqrt{{\frac{{{{{\sum\limits_{{i=1}}^{m}{{\left( {x-{{\mu }_{x}}} \right)}}}}^{2}}}}{{m-1}}}}=\sqrt{{\frac{{{{{\sum\limits_{{i=1}}^{m}{{\left( {x-{{x}_{{\text{mean}}}}} \right)}}}}^{2}}}}{{m-1}}}}

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">std(</span>M<span style="color: #808080;">,</span>weight<span style="color: #808080;">,</span>direction<span style="color: #0000ff;">)</span>
M=<span style="color: #ff0000;">[</span>1<span style="color: #808080;">,</span>2<span style="color: #808080;">,</span>3<span style="color: #ff00ff;">;</span>4<span style="color: #808080;">,</span>5<span style="color: #808080;">,</span>6<span style="color: #ff00ff;">;</span>7<span style="color: #808080;">,</span>8<span style="color: #808080;">,</span>9<span style="color: #ff0000;">]</span>

\displaystyle \text{M}=\left[ {\begin{array}{*{20}{c}} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{array}} \right]

\displaystyle \text{mean}\left( {\text{M,1}} \right)=\left[ {\begin{array}{*{20}{c}} 4 & 5 & 6 \end{array}} \right]

Using 1 input matrix, skipping the second input, the weight using

<span style="color: #ff6600;">[</span> <span style="color: #ff6600;">]</span>

and specifying the direction as 1 (Direction 1 finds the Standard Deviation in each Column)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">std(</span>M<span style="color: #808080;">,</span><span style="color: #ff6600;">[]</span><span style="color: #808080;">,</span>1<span style="color: #0000ff;">)</span>

\displaystyle \text{std}\left( {\text{M},\left[ {} \right],1} \right)=\left[ {\begin{array}{*{20}{c}} {\text{var}\left( {\begin{array}{*{20}{c}} 1 \\ 4 \\ 7 \end{array}} \right)} & {\text{var}\left( {\begin{array}{*{20}{c}} 2 \\ 5 \\ 8 \end{array}} \right)} & {\text{var}\left( {\begin{array}{*{20}{c}} 3 \\ 6 \\ 9 \end{array}} \right)} \end{array}} \right]

\displaystyle \text{std}\left( {\text{M},\left[ {} \right],1} \right)=\left[ {\begin{array}{*{20}{c}} {\sqrt{{\frac{{{{{\left( {1-4} \right)}}^{2}}+{{{\left( {4-4} \right)}}^{2}}+{{{\left( {7-4} \right)}}^{2}}}}{{3-1}}}}} & {\sqrt{{\frac{{{{{\left( {2-5} \right)}}^{2}}+{{{\left( {5-5} \right)}}^{2}}+{{{\left( {8-5} \right)}}^{2}}}}{{3-1}}}}} & {\sqrt{{\frac{{{{{\left( {3-6} \right)}}^{2}}+{{{\left( {6-6} \right)}}^{2}}+{{{\left( {9-6} \right)}}^{2}}}}{{3-1}}}}} \end{array}} \right]

\displaystyle \text{std}\left( {\text{M},\left[ {} \right],1} \right)=\left[ {\begin{array}{*{20}{c}} 3 & 3 & 3 \end{array}} \right]

\displaystyle \text{std}\left( {\text{M},\left[ {} \right],1} \right)=\sqrt{{\text{var}\left( {\text{M},\left[ {} \right],1} \right)}}

Using 1 input matrix, skipping the second input, the weight using

<span style="color: #ff6600;">[</span> <span style="color: #ff6600;">]</span>

and specifying the direction as 2 (Direction 2 finds the Standard Deviation in each Row)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">std(</span>M<span style="color: #808080;">,</span><span style="color: #ff6600;">[]</span><span style="color: #808080;">,</span>2<span style="color: #0000ff;">)</span>

\displaystyle \text{std}\left( {\text{M},\left[ {} \right],2} \right)=\left[ {\begin{array}{*{20}{c}} {\text{std}\left( {\begin{array}{*{20}{c}} 1 & 2 & 3 \end{array}} \right)} \\ {\text{std}\left( {\begin{array}{*{20}{c}} 4 & 5 & 6 \end{array}} \right)} \\ {\text{std}\left( {\begin{array}{*{20}{c}} 7 & 8 & 9 \end{array}} \right)} \end{array}} \right]

\displaystyle \text{std}\left( {\text{M},\left[ {} \right],2} \right)=\left[ {\begin{array}{*{20}{c}} {\sqrt{{\frac{{{{{\left( {1-2} \right)}}^{2}}+{{{\left( {2-2} \right)}}^{2}}+{{{\left( {3-2} \right)}}^{2}}}}{3}}}} \\ {\sqrt{{\frac{{{{{\left( {4-5} \right)}}^{2}}+{{{\left( {5-5} \right)}}^{2}}+{{{\left( {6-5} \right)}}^{2}}}}{3}}}} \\ {\sqrt{{\frac{{{{{\left( {7-8} \right)}}^{2}}+{{{\left( {8-8} \right)}}^{2}}+{{{\left( {9-8} \right)}}^{2}}}}{3}}}} \end{array}} \right]

\displaystyle \text{std}\left( {\text{M},\left[ {} \right],2} \right)=\left[ {\begin{array}{*{20}{c}} 1 \\ 1 \\ 1 \end{array}} \right]

\displaystyle \text{std}\left( {\text{M},\left[ {} \right],2} \right)=\sqrt{{\text{var}\left( {\text{M},\left[ {} \right],1} \right)}}

Using only 1 input matrix, skipping the second input matrix using

<span style="color: #ff6600;">[</span> <span style="color: #ff6600;">]</span>

and specifying the direction as all (Direction all finds the Standard Deviation of the entire Matrix)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">std(</span>M<span style="color: #808080;">,</span><span style="color: #ff6600;">[]</span><span style="color: #808080;">,</span><span style="color: #800080;">'</span>all<span style="color: #800080;">'</span><span style="color: #0000ff;">)</span>

\displaystyle \text{std}\left( {\text{M},\left[ {} \right],'\text{all}'} \right)=\text{std}\left( {\text{M(:)}} \right)=\text{std}\left( {\left[ {\begin{array}{*{20}{c}} 1 \\ 4 \\ 7 \\ 2 \\ 5 \\ 8 \\ 3 \\ 6 \\ 9 \end{array}} \right]} \right)

\displaystyle \text{std}\left( {\text{M},\left[ {} \right],'\text{all}'} \right)=\sqrt{{\text{var}\left( {\text{M},\left[ {} \right],'\text{all }\!\!'\!\!\text{ }} \right)}}

cumsum function

Calculates the cumulative sum:

\displaystyle \text{V=}\left[ {\begin{array}{*{20}{c}} \text{A} \\ \text{B} \\ \text{C} \end{array}} \right]

\displaystyle \text{cumsum}\left( \text{V} \right)=\left[ {\begin{array}{*{20}{c}} \text{A} \\ {\text{A+B}} \\ {\text{A+B+C}} \end{array}} \right]

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">cumsum(</span>M<span style="color: #808080;">,</span>direction<span style="color: #0000ff;">)</span>
M=<span style="color: #ff0000;">[</span>1<span style="color: #808080;">,</span>2<span style="color: #808080;">,</span>3<span style="color: #ff00ff;">;</span>4<span style="color: #808080;">,</span>5<span style="color: #808080;">,</span>6<span style="color: #ff00ff;">;</span>7<span style="color: #808080;">,</span>8<span style="color: #808080;">,</span>9<span style="color: #ff0000;">]</span>

Inputting the input matrix M and specifying the Direction as 1 (Direction 1 finds the Cumulative Sum going down in each Column)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">cumsum(</span>M<span style="color: #808080;">,</span>1<span style="color: #0000ff;">)</span>

\displaystyle \text{cumsum(M,1)}=\left[ {\text{cumsum}\begin{array}{*{20}{c}} {\left[ {\begin{array}{*{20}{c}} 1 \\ 4 \\ 7 \end{array}} \right]} & {\text{cumsum}\left[ {\begin{array}{*{20}{c}} 2 \\ 5 \\ 8 \end{array}} \right]} & {\text{cumsum}\left[ {\begin{array}{*{20}{c}} 3 \\ 6 \\ 9 \end{array}} \right]} \end{array}} \right]

\displaystyle \text{cumsum(M,1)}=\left[ {\begin{array}{*{20}{c}} 1 & 2 & 3 \\ {1+4} & {2+5} & {3+6} \\ {1+4+7} & {2+5+8} & {3+6+9} \end{array}} \right]

\displaystyle \text{cumsum(M,1)}=\left[ {\begin{array}{*{20}{c}} 1 & 2 & 3 \\ 5 & 7 & 9 \\ {12} & {15} & {18} \end{array}} \right]

Inputting the input matrix M and specifying the Direction as 1 (Direction 2 finds the Cumulative Sum going down in each Row)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">cumsum(</span>M<span style="color: #808080;">,</span>2<span style="color: #0000ff;">)</span>

\displaystyle \text{cumsum(M,2)}=\left[ {\begin{array}{*{20}{c}} {\text{cumsum}\left[ {\begin{array}{*{20}{c}} 1 & 2 & 3 \end{array}} \right]} \\ {\text{cumsum}\left[ {\begin{array}{*{20}{c}} 4 & 5 & 6 \end{array}} \right]} \\ {\text{cumsum}\left[ {\begin{array}{*{20}{c}} 7 & 8 & 9 \end{array}} \right]} \end{array}} \right]

\displaystyle \text{cumsum(M,2)}=\left[ {\begin{array}{*{20}{c}} 1 & {1+2} & {1+2+3} \\ 4 & {4+5} & {4+5+6} \\ 7 & {7+8} & {7+8+9} \end{array}} \right]

\displaystyle \text{cumsum(M,2)}=\left[ {\begin{array}{*{20}{c}} 1 & 3 & 6 \\ 4 & 9 & {15} \\ 7 & {15} & {24} \end{array}} \right]

cumprod function

Calculates the cumulative product:

\displaystyle \text{V=}\left[ {\begin{array}{*{20}{c}} \text{A} \\ \text{B} \\ \text{C} \end{array}} \right]

\displaystyle \text{cumprod(V)}=\left[ {\begin{array}{*{20}{c}} \text{A} \\ {\text{A}*\text{B}} \\ {\text{A}*\text{B}*\text{C}} \end{array}} \right]

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">cumprod(</span>M<span style="color: #808080;">,</span>direction<span style="color: #0000ff;">)</span>
M=<span style="color: #ff0000;">[</span>1<span style="color: #808080;">,</span>2<span style="color: #808080;">,</span>3<span style="color: #ff00ff;">;</span>4<span style="color: #808080;">,</span>5<span style="color: #808080;">,</span>6<span style="color: #ff00ff;">;</span>7<span style="color: #808080;">,</span>8<span style="color: #808080;">,</span>9<span style="color: #ff0000;">]</span>

Inputting the input matrix M and specifying the Direction as 1 (Direction 1 finds the Cumulative Product going down in each Column)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">cumprod(</span>M<span style="color: #808080;">,</span>1<span style="color: #0000ff;">)</span>

\displaystyle \text{cumprod(M,1)}=\left[ {\text{cumprod}\begin{array}{*{20}{c}} {\left[ {\begin{array}{*{20}{c}} 1 \\ 4 \\ 7 \end{array}} \right]} & {\text{cumprod}\left[ {\begin{array}{*{20}{c}} 2 \\ 5 \\ 8 \end{array}} \right]} & {\text{cumprod}\left[ {\begin{array}{*{20}{c}} 3 \\ 6 \\ 9 \end{array}} \right]} \end{array}} \right]

\displaystyle \text{cumprod(M,1)}=\left[ {\begin{array}{*{20}{c}} 1 & 2 & 3 \\ {1*4} & {2*5} & {3*6} \\ {1*4*7} & {2*5*8} & {3*6*9} \end{array}} \right]

\displaystyle \text{cumprod(M,1)}=\left[ {\begin{array}{*{20}{c}} 1 & 2 & 3 \\ 4 & {10} & {18} \\ {28} & {80} & {162} \end{array}} \right]

Inputting the input matrix M and specifying the Direction as 2 (Direction 2 finds the Cumulative Sum Value going down in each Row)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">cumprod(</span>M<span style="color: #808080;">,</span>2<span style="color: #0000ff;">)</span>

\displaystyle \text{cumprod(M,2)}=\left[ {\begin{array}{*{20}{c}} {\text{cumprod}\left[ {\begin{array}{*{20}{c}} 1 & 2 & 3 \end{array}} \right]} \\ {\text{cumprod}\left[ {\begin{array}{*{20}{c}} 4 & 5 & 6 \end{array}} \right]} \\ {\text{cumprod}\left[ {\begin{array}{*{20}{c}} 7 & 8 & 9 \end{array}} \right]} \end{array}} \right]

\displaystyle \text{cumprod(M,2)}=\left[ {\begin{array}{*{20}{c}} 1 & {1*2} & {1*2*3} \\ 4 & {4*5} & {4*5*6} \\ 7 & {7*8} & {7*8*9} \end{array}} \right]

\displaystyle \text{cumprod(M,2)}=\left[ {\begin{array}{*{20}{c}} 1 & 2 & 6 \\ 4 & {20} & {120} \\ 7 & {56} & {504} \end{array}} \right]

diff function

Calculates the difference (approximate derivative) between Matrix elements:

\displaystyle \text{V}=\left[ {\begin{array}{*{20}{c}} \text{A} \\ \text{B} \\ \text{C} \end{array}} \right]

\displaystyle \text{diff(V)}=\left[ {\begin{array}{*{20}{c}} {\text{B}-\text{A}} \\ {\text{C}-\text{B}} \end{array}} \right]

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">diff(</span>M<span style="color: #808080;">,<span style="color: #000000;">order</span>,</span>direction<span style="color: #0000ff;">)</span>
M=<span style="color: #ff0000;">[</span>1<span style="color: #808080;">,</span>2<span style="color: #808080;">,</span>3<span style="color: #ff00ff;">;</span>4<span style="color: #808080;">,</span>5<span style="color: #808080;">,</span>6<span style="color: #ff00ff;">;</span>7<span style="color: #808080;">,</span>8<span style="color: #808080;">,</span>9<span style="color: #ff0000;">]</span>

Using 1 input matrix, skipping the second input, the weight using

<span style="color: #ff6600;">[</span> <span style="color: #ff6600;">]</span>

and specifying the Direction as 1 (Direction 1 finds the Diff going down in each Column)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">diff(</span>M<span style="color: #808080;">,<span style="color: #ff6600;">[]</span>,</span>1<span style="color: #0000ff;">)</span>

\displaystyle \text{diff(M,}\left[ {} \right]\text{,1)}=\left[ {\begin{array}{*{20}{c}} {\text{diff}\left( {\left[ {\begin{array}{*{20}{c}} 1 \\ 4 \\ 7 \end{array}} \right]} \right)} & {\text{diff}\left( {\left[ {\begin{array}{*{20}{c}} 2 \\ 5 \\ 8 \end{array}} \right]} \right)} & {\text{diff}\left( {\left[ {\begin{array}{*{20}{c}} 3 \\ 6 \\ 9 \end{array}} \right]} \right)} \end{array}} \right]

\displaystyle \text{diff(M,}\left[ {} \right]\text{,1)}=\left[ {\begin{array}{*{20}{c}} {4-1} & {5-2} & {6-3} \\ {7-4} & {8-5} & {9-6} \end{array}} \right]

\displaystyle \text{diff(M,}\left[ {} \right]\text{,1)}=\left[ {\begin{array}{*{20}{c}} 3 & 3 & 3 \\ 3 & 3 & 3 \end{array}} \right]

Using 1 input matrix, skipping the second input, the weight using

<span style="color: #ff6600;">[</span> <span style="color: #ff6600;">]</span>

and specifying the Direction as 2 (Direction 2 finds the Diff going across each Row)

<span style="color: #ff0000;">[</span>Output<span style="color: #ff0000;">]</span>=<span style="color: #0000ff;">diff(</span>M<span style="color: #808080;">,<span style="color: #ff6600;">[]</span>,</span>2<span style="color: #0000ff;">)</span>

\displaystyle \text{diff(M,}\left[ {} \right]\text{,2)}=\left[ {\begin{array}{*{20}{c}} {\text{diff}\left( {\left[ {\begin{array}{*{20}{c}} 1 & 2 & 3 \end{array}} \right]} \right)} \\ {\text{diff}\left( {\left[ {\begin{array}{*{20}{c}} 4 & 5 & 6 \end{array}} \right]} \right)} \\ {\text{diff}\left( {\left[ {\begin{array}{*{20}{c}} 7 & 8 & 9 \end{array}} \right]} \right)} \end{array}} \right]

\displaystyle \text{diff(M,}\left[ {} \right]\text{,2)}=\left[ {\begin{array}{*{20}{c}} {2-1} & {3-2} \\ {5-4} & {6-5} \\ {8-7} & {9-8} \end{array}} \right]

\displaystyle \text{diff(M,}\left[ {} \right]\text{,2)}=\left[ {\begin{array}{*{20}{c}} 1 & 1 \\ 1 & 1 \\ 1 & 1 \end{array}} \right]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.