Getting Started with MATLAB
Installation (Windows & Mac)
- First you need to create a Mathworks account using your long imperial email (e.g. name.surname21@imperial.ac.uk).
- Mathworks will recognize your Imperial email and ask you to log in from through the Imperial portal.
- Finalize the creation of your Mathworks account.
- Mathworks should have granted an educational Matlab license, you should be able to download and install it as you would normally expect.
Interface
When you first install Matlab, your interface should look like this, it should have 3 main panels.
Current folder, on this panel you can view and access your files.
Command Window, on this panel you can enter commands and interact with variables in real-time. This panel is where most of the action will happen!
Workspace, on this panel you can see all your declared variables, their type and their value.
Declaring variables and basic operations
Declare variables
The following command will create a variable called a with the value of 34
a = 34
Many more variables can be created
b = 21
These variables can be used to create new variables!
c = a + b
c =
55
Basic Operators
- Addition “+”
- Subtraction “-“
- Multiplication “*”
- Division “/”
- Power “^”
These can be used to create all sort of operations:
d = (a * b)/c
d =
12.9818
Useful information
- If you finish your command with a ”;” the result will not be displayed.
-
When Matlab does an operation without declaring a variable, the result gets stored in a variable called ans, exactly like physical calculators do!
45 - 67 ans = -22
- Pressing the up and down arrows on the command line will allow you to “recall” commands, give this a try to understand it.
- Press tab to autocomplete commands.
- To delete variables from the workspace use the clear command, clear all will delete all of the variables.
clear a b c d
- Use clc to clear the Command panel and keep things tidy.