Escolar Documentos
Profissional Documentos
Cultura Documentos
Definitions
Vectors and matrices: set of elements (array).
row(2)
Creating a subvector
sub1=row(2:4) %Sequential indexes
sub1(2)=16
sub1(4)=22
Decreasing vector
vec_dec=10:-2:1
rowtrans = row'
Creating matrices and basic commands to deal with them
mat=[1 2 3
4 5 6] %The rows can be divided in lines.
mat=[1:3;4:6]
mat(1) %it will refer to the element of the first row, first column
mat(5) %it will refer to the element in the first row, column tree.
mat(4,:)=[20 30 40] % Adds the row No. 4 and fills the 3rd with zeros.
mat =
1 20 3
20 30 40
0 0 0
20 30 40
mat(:,5)= [20 30 40 50]' %Adds the row No. 4 and fills the 3rd with zeros.
mat =
1 20 3 0 20
20 30 40 0 30
0 0 0 0 40
20 30 40 0 50
mat =
1 20 3 0
20 30 40 0
0 0 0 0
20 30 40 0
mat =
1 20 3 0
20 30 40 0
A =
1 2 3
4 5 6
7 8 9
B=A'
B =
1 4 7
2 5 8
3 6 9
Multiplication
B*A
ans =
66 78 90
78 93 108
90 108 126
a=[4 9 1]
a =
4 9 1
a*B
ans =
25 67 109
B =
1 4 7
2 5 8
3 6 9
A.*B
ans =
1 8 21
8 25 48
21 48 81
A+B
A-B
Division
A./B
B./A %The order matters
A.\B %Elementwise but dividing the elements from B by the one from A
Potencies
Z =
0 0
0 0
0 0
z =
0
0
0
Ones =
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
ans =
1 0 0 0
0 1 0 0
r=[1 2; 3 4]
r =
1 2
3 4
ans =
1 2 1 2 1 2
3 4 3 4 3 4
1 2 1 2 1 2
3 4 3 4 3 4
1 2 1 2 1 2
3 4 3 4 3 4
1 2 1 2 1 2
3 4 3 4 3 4
ans =
0.8147 0.9134
0.9058 0.6324
0.1270 0.0975
ans =
-2 -4 3 3 4
1 5 -4 5 5
5 5 -1 2 2
5 0 5 -5 3
ls =
3 6 9 12 15
Hypermatrices:
One matrix of i x j dimensions and k "layers".
% Example
AA(:,:,1)=[1 2 3; 4 5 6]
AA(:,:,2)=[2 3 4; 5 6 7]
%Example
AA(:,:,2)