MATLAB Programming/Vector and Matrices/Operations on Vectors

Constructing Vectors
If a vector's elements is following the sequential additions, we can just use parentheses with the following:

$$ Vector = ( first_number_in_the_matrix : incremental_value : last_number_in_the_vector ) $$ As for example, if we want to have a vector starting with number 1 and ends with number 19 with the incremental values of 3, we can type commands shown below

Accessing Vector
To access the values in vector, you just need to specify the vector and the array index, from 1 to n.

Using example of vector V above, we access single elements of vector V in third elements which we type commands as followed:

We can access multiple elements by typing the start index and the end index For example, we need to access element no 3 up to element no 6, we type as followed:

Finding Length
We can also use length function to knows what is the length of the vector ,for example we can know what is the length of V. There are 7 elements in vector V, therefore the answer should be 7

Sum Vector
We can find the sums of vector using sum function, it get this values by adding all of the numbers inside vector together: For example, 1+4+7+10+13+16+19

Finding Max and Min
Respectively we can know which is the biggest and smallest number in a vector which we can use by using min and max functions

Finding Mean
The mean function is to find the center/middle value inside the vector

Finding Average
The average function is to find the average of the vector

Finding Standard Deviation
To find standard deviation, std function is needed The standard deviation is a measure of the amount of variation or dispersion of a set of values. A low standard deviation indicates that the values tend to be close to the mean (also called the expected value) of the set, while a high standard deviation indicates that the values are spread out over a wider range.

Random Permutation
There are two different ways to create random permutations for vector

a. randperm(N) returns a vector containing a random permutation of the integers 1:N.

b. randperm(N,K) returns a row vector containing K unique integers selected randomly from 1:N

Sorting Vector
You may want to sort the vectors, you can do this MATLAB.

If the vectors are to be sorted in descending manner, use this example as followed. Note, we use the random permutation example b above.

Calculating dot products
To find dot product,you can use the dot functions

NOTE: The two vectors must have the same length. The answer will usually in the forms of scalar.

The dot product of vector are calculated as followed

$$ A = [A1,A2,A3,...,An] $$

$$ B = [B1,B2,B3,...,Bn] $$

$$ A.B = A1.B1 + A2.B2 + A3.B3 + ... + An.Bn $$

Calculating cross products
To find cross product,you can use the cross functions NOTE: The two vectors must have the same length of 3. The answer will usually in the forms of vector 3.

TODO: Search a picture that can illustrate the cross product well.

Calculating commonly used values in vector
To find the most duplicated values in the vector, we can use the mode functions.