Getting started with octave – Matrices

Create a 2×3 matrix. Each row is a comma-separated list of elements. Rows are separated by a semicolon.

A = [1, 2, 3; 4, 5, 6]

# A =
#
#   1   2   3
#   4   5   6

Sum of two matrices

B = [1, 1, 1; 1, 1, 1]

# B =
#
#    1   1   1
#    1   1   1

A+B

# ans =
#
#   2   3   4
#   5   6   7

Multiply matrix by a scalar

2*A

# ans =
#
#    2    4    6
#    8   10   12

Matrix multiplication

C = [1, 0; 0, 0; 0, 1]

# C =
#
#   1   0
#   0   0
#   0   1

A*C

# ans =
#
#   1   3
#   4   6

A matrix can be a column vector

C = [2; 0; 1]

# C =
#
#   2
#   0
#   1

A * C
# ans =
# 
#     5
#    14

Concatenating matrices

For horizontal concatenation, that is joining two block matrices column-wise

A= [1,2;3,4]; 
B=[4,3;2,1];
C=horzcat(A,B);
disp(C)
# C=
#
# 1 2 4 3 
# 3 4 2 1 




if you want to reproduce, please indicate the source:
Getting started with octave – Matrices - CodeDay