clc
clear all

% First way to create the matrix A
A = [1 2 3 4; 5 6 7 8; 9 10 11 12]

% or
v = 1:12 % or v = 1:1:12
v1 = v(1:4)
v2 = v(5:8)
v3 = (9:12)
A = [v1; v2; v3]

% or
col1 = [1 5 9]'
col2 = [2 6 10]'
col3 = [3 7 11]'
col4 = [4 8 12]'
A = [col1 col2 col3 col4]

% or
A1 = [col1 col2]
A2 = [col3 col4]
A = [A1 A2]

% We want to set the element in position (2, 3) to -1
A(2, 3) = -1

% We want to set the whole second line to -1
A(2, :) = -1

% Change the second column as [1 0 -1]
A(:, 2) = [1 0 -1]

% Create the matrix B equal to A but with the first left half part of it
% equal to 1
B = A
B(:, 1:2) = 1

% Now we want to set the second right half of B to 0
B(:, end-1:end) = 0 % or B(:, 3:4) = 0

% We want to set the elements in position (1, 1), (1, 4),
% (3, 1) and (3, 4) equal to 2
A([1 3], [1 4]) = 2

% C = A + B
C = A + B

% Get the size of a matrix
size(A)

% Get the number of rows
size(A, 1)

% Get the number of columns
size(A, 2)

% Get the number of elements of the array v
length(v)
numel(v)

%{
    Be careful because with matrixes
    the two instructions give you different results
    N.B.: this is a comment distributed in more than one line
    that avoids you to put a % at the beginning of each line.
%}
length(A)
numel(A)

% Multiplication by a scalar
D = 2*A

% Mixed expression
E = A - 2*B + 3*C - D

% Transpose of a matrix
A
F = A' % A transposed

% We want to delete the first row of F
F(1, :) = []

% We want to delete the first and third column
F(:, [1 3]) = []