% I define an array with natural numbers from
% 1 to 10
v1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

% or
v1 = 1:10;
disp("The number of elements is:")
length(v1)

%{
This solution is not very elegant to see.
If we want to show everything in a single line,
we use the sprintf() function
%}
auxString = sprintf("The number of element is: %d", length(v1));
disp(auxString)

name = 'Mauro'
age = 40
auxString = sprintf("My name is %s and I am %d years old", ...
    name, age);
disp(auxString)

v2 = [1, 2, 4, 7]'

%{ 
    v1 is a row vector and it can be seen as a matrix with
    one row and ten columns.
    v2 is a column vector and it can be seen as a matrix
    with 4 rows and 1 column.
    In MAtlab there is a special function that gives me the size
    of a matrix, i.e, the number of rows and columns.
%}
size(v1)
numRows = size(v1, 1);
numColumns = size(v1, 2);
auxString = sprintf("Number of rows of v1: %d", numRows);
disp(auxString)
auxString = sprintf("Number of columns of v1: %d", numColumns);
disp(auxString)
size(v2)
auxString = sprintf("Number of rows of v2: %d", size(v2, 1));
disp(auxString)
auxString = sprintf("Number of columns of v2: %d", size(v2, 2));
disp(auxString)
s1 = "This is a string";
s2 = 'This is another string';
disp(s1)
disp(s2)
auxString = sprintf("v1 = [%s]", num2str(v1));
disp(auxString)

% I want to change the element in position 3 and set it equal
% to 5
v1(3) = 5;
auxString = sprintf("v1 = [%s]", num2str(v1));
disp(auxString)

% I want to delete the element in position 3
v1(3) = [];
auxString = sprintf("v1 = [%s]", num2str(v1));
disp(auxString)

% I want to set the elements in positions 1, 2 and 7 equal to 0
%v1(1) = 0    % slow way
%v1(2) = 0
%v1(7) = 0
v1([1, 2, 7]) = 0;
auxString = sprintf("v1 = [%s]", num2str(v1));
disp(auxString)

% I want to delete the elements in position 2, 4, and 7
v1([2, 4, 7]) = [];
auxString = sprintf("v1 = [%s]", num2str(v1));
disp(auxString)

% I redefine vector v2
v2 = [2, 4, 6, 8, 10];
auxString = sprintf("v2 = [%s]", num2str(v2));
disp(auxString)

% or
v2 = 2:2:10;
auxString = sprintf("v2 = [%s]", num2str(v2));
disp(auxString)

% or I can use the linspace(a, b, n) function
% It creates an array of n equally-spaced elements from a to b.
v2 = linspace(2, 10, 5);
auxString = sprintf("v2 = [%s]", num2str(v2));
disp(auxString)

% The linspace function is used to make the graphs
% For instance, I want to draw the parabola y = x^2 - 2*x + 1
x = linspace(-2, 3, 2000);
y = x.^2 - 2*x + 1;
plot(x, y)
xlabel('x')
ylabel('y')
title("y = x^2 - 2x + 1")
grid % or grid on
y = sin(x);
hold on
plot(x, y)

figure
y1 = x.*sin(x);
y2 = x.*log(1 + x);
plot(x, y1, 'r', x, y2, 'g')
grid on