Introduction
Matlab is a computational tool based on matrices and matrix operations, even unit variables can be considered as arrays of one dimension and a single element. The matrix in Matlab is the same matrix that we learned in college, they are mxn tables of symbols represented in the table form of m rows and n columns.

Creating variables and using Matlab as a Calculator
In this part we will see in how to create variables in Matlab also create simple expressions with those variables. Simply enter any name and assign a value that a variable will be created. Example:
pi = 3.14;
r = 10;
Those commands will create a "pi" variable with value "3.14", the ";" operator is used to avoid the command to be echoed on the matlab workspace.
a = 2 * pi * 3
a = 62.8000
Using the "whos" command we can see all variables used:
Let's list some important commands:
- clear (erase all variables)
- clc ( Clean all screen content)
- close all (Close all open figures)
- size (Returns the size of some variable)
Now let's see some more complicated expressions:
Creating Vectors
Vectors are matrices with unit dimension, normally used to represent unit dimension signals, like time:
the first example we create a vector "x" that begins with value "a" and end with value "b" using "dx" steps to get from "a" to "b", for example:
t = 0:0.1:50
Vector "t" begin in 0 and end in 50 with 0.1 steps.
Creating Matices
In matlab we create matrix like this:
In other words, every space or "," we have a new column and each semicolon ";" we have a new line, for example:
A = [1 1 1; 2 2 2]
We have a matrix with 2 lines and 3 columns
Indexing matrices
Indexing matrices means to access any element of the matrix or range of elements, or even a sub-matrix of the given matrix. Matlab indexing of elements is made in the form Matrix (row,column). An important observation is that in Matlab the Vectors and matrices start at element 1, unlike the C language which elements of the array starting at 0.
(2,3) will access the element that is in the second row and third column, in this case the element 6.
In the other case block1 will be the sub-matrix of matrix A from row 2 with columns 1 and 2.
Another way to index elements of the arrays is using the operator ":" that can
be used to define a range of elements.
The operator ":" if used alone can indicate "all elements" of the columns or rows of a matrix
row2 = A (2,:)
This command will select all columns of row 2, ie
row2 = [4 5 6]
Matrix operations
Let's see now some major matrix operations:
- Plus (+)
- Minus (-)
- Multiplication (*)
- Concatenation (B = [A, A])
- Trasposing matrix (B = 'A)
Bellow we ilustrate the matrix operations with a linear system of equations being solved numerically.
Element to Element operations
In the previous cases we have seen matrix math operations, but sometimes we want to do the operations element by element in each matrix position, for example if we multiply a 2D matrix representing an image, by a matrix of the same size, however only with elements 0 or 1, we have an mask operation.
Function visualization (plots)
So far we have seen expressions are validated for a single entry (eg t = 0.2), now we're going to evaluate the expression for all time "t" and then Plot the result in a graph.
In the commands below we define a sine function with a time t of 5 seconds. The amplitude equal to 2 and frequency w equal to 1