We have explored how to run basic arithmetic calculations using the command window in the last article. Now, we shall explore MATLAB’s main purpose- working with vectors and matrices, by making and running our first script.
To start, let us set the habit of header blocks at the very beginning of each script. This will help us organize our scripts later down the line. If you are unsure of a proper way to format your header block, here is an example: (img)

In our case, this script will be about finding the mean and variance of a vector A, so let’s classify it as such: (img)

With our header block classifier done, let’s move on to the purpose of the script.
Let’s assume that we have a vector A: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 ];. We can assign it like this: (img)

To start, let’s say we want to find the sum of our vector A. Luckily, the sum() function will do this for us:

Following up, let’s say we need the amount of <<numbers>> inside our vector A, otherwise known as the length of A. We can use the length() function to accomplish this task:

Now we wish to find the mean value of our vector A, which is given by the formula:
Where N is the length of the vector, and k is the index position.
We can once again use the handily available functions sum() and length() to re-build the formula: (img)

Which will yield us our mean, mu:

Conversely, there is also a function, mean() that can accomplish this task for us:

We can see that the mean value of our vector A is 4.5.