A short description of the post.
Today I am going to attempt to learn MATLAB (Matrix Laboratory). MATLAB is a matrix based language geared towards engineers and scientists. With MATLAB one can
I need MATLAB so I can run the algorithm from Dong et. al. and compare results with my version that is implemented in python.
My hope is learning basic MATLAB will give me a clearer understanding of the algorithm.
When you open MATLAB most of the screen will be occupied by the Command Window. This functions much like the terminal with python. Here you can input simple commands. The Current Folder will show your current working directory. Notice this is very similar to RStudio. The Workspace window will show values of variables. The PLOT tab is where graphics will be displayed, and the APP tab will show different apps you can add (similar to adding packages in R).
The Command Window and Workspace will be the most important.
The basic arithmetic opperations for python are +, -, *, and /. The ‘=’ sign is used for assignment.
double clicking the top of a window will enlarge and minimize it.
If we enlarge the **Workspace*, we can right click (control click on macbook) and select several different properties to be displayed.
We can clear our command window by running the command ‘clc’. We can in turn hit the up arrow key to scroll through all previous commands that have been run in a given session.
Running the command ‘whos’ will display the workspace.
If we want to clear our workspace we can use the command ‘clear all’. We can delete a single variable, ‘a’, by the command ‘clear a’.
By default, every variable defined in MATLAB will be a matrix. When we assign a single integer to a variable, MATLAB stores this as \(1\times 1\) matrix.
We can create a matrix of arbitrary size by:
‘a = [ 9 8 8;]’
will creat a \(1\times 3\) matrix.
‘a = [ 1 1 1; 2 2 2; 3 3 3;]’
will create the matrix:
\[\begin{bmatrix} 1&1&1\\ 2&2&2\\ 3&3&3\\ \end{bmatrix}\]If we now expand our workspace, we can click on our variable ‘a’, and see the matrix displayed in an excel-like grid. We can now use some of the other attributes in our workspace like min, max, mean, median, ect.
We can right click our variable in our workspace and preform some useful operations like; rename it, change its value, duplicate it and make various plots if its is the correct size.
We can also save the variable as .mat file.
We can load a .mat file with the ‘load(FILENAME.mat)’.
So far, we have only used numeric variables. We can have character variables char. The command
a = ‘hello world’
will create a \(1\times 11\) character matrix.
We can add a row to matrix, a, with the following:
a(2,:) = a(1,:)
This will output
‘hello world’
‘hello world’
Note: you must make sure the rows are the same size when adding them
We can get around this by using strings.
We can create an empty string with:
a = [string(‘Hi how ar you’) string(‘hello world’)]
output:
a =
1×2 string array
"Hi how ar you" "hello world"