As shown in the figure.
Row vector:
Column vector:
Rules
row * column [ inner product ]
a * b =
column * row [ outer product ]
b * a =
Enter a Matrix
If we want to enter a Matrix,we use semicolon(;) to separate different rows.
Array Indexing
If we want to select a certain subset of elements inside a Matrix.
Vector
Matrix
一、we can use A(1,1) to select a certain subset element.
二、we could also use A(n)
If the elements in the matrix are selected as A(n),then n is A linear structure stored as column.
then if we use
In this way,we can creat a matrix by A(1),A(3)
There is a special case here.
The first [1,3] means the first row and third row.
The second[1,3] means the first column and third column.
and
The interleaved row and column form a new matrix.
Replacing Entries
As shown in the figure
Colon Operator
Want to create a long Array: A = [1 2 3 4 5 6...100]
Create vectors or arrays,and specify for iterations
we could use colon operator( : ) to simplify our opertions
For instance ( Syntax )
If we want to set up an arithmetic iteration
We can use colon operator to create a matrix conveniently
Find and Kill the rows or columns in the matrix
we could use colon operator find the row or column
Kill the row or column,we pass an empty vector to the row or column that we select.
Array Concatenation
Array can be formed through concatenation as long as the rectangular shape is preserved.
Methods A
In this way, we could set the "u"and "y" matrix as new matrix with column.
Methods B
In this way, the new matrices are linked by rows of u and y matrices.
Array Manipulation
Operators on array: + - * / ^ . '
The '.' operator can be used with other operators.
For instance
we can get a true matrices multiplication when we only use single operator " * ".
We can manipulate two matrice with a single "+" to get a new matrix that adds the corresponding positions.
The "+" operator is used with a real number means create a new matrix that adds the real number with the corresponding positions.
The " ' " operator means exchange of positional elements around the diagonal.
The rest of the operators can be inferred by common sense.
Some special matrix
eye(n):
zeros(n1,n2):
ones(n1,n2):
Similar to the above.
diag():
Set the diagonal with a vector similar to [1 2 3 4 5]
And
The rest of positions are set with zeros.
Some special Related functions
As shown in the figure:
Demo
max() / min() / max(max())
The max() function can be used to pick up the max member of every row form a new vector.
If we want to select the max element in the matrix
sum()
get the sum of the elements of each column.
mean()
get the mean of the elements of each column.
sort()/sortrows()
we can use these commands to sort columns or rows
As shown in the figure
the result of these commands
We can easily find that the row with the biggest value is moved to the top.
The rest of the commands can be easily understood
As shown in the figure
size()
The num of rows and column.
length()
The num of vector.
fine()
We can find whether a element we select in the matrix.It will return a index,if the value can be find in this matrix.
It will return an empty vector when the element not existed