DiscW1-MatlabCheatsheet
DiscW1-MatlabCheatsheet
When you open Matlab you will see the following (note that the windows within Matlab may
be arranged slightly di↵erently)
Calculations can be done either in the ”Command window” or the ”Editor”. The command
window is a temporary place to see your commands, the commands themselves are saved in the
”Command history”, but not the answers. The solution to the calculation is displayed in the
”Command Window” and stored in the ”Workspace”. If you do not assign a variable name to the
calculation, the answer is stored in the default variable name ”ans” .
2
For example, if we want to add 3 + 5, we can type: 3 + 5 in the Command Window.
Note that at this point, the answer is a variable of size (m,n) where m is the number of rows,
and n is the number of columns. For this example, A is a 1x1 array.
Often, you will be adding vectors - your variable would then be a 1x2 vector array (for 2-D
problems) or a 1x3 array (for 3-D problems).
General guidelines
• Perform secondary calculations using these variables and save this as another variable (e.g.
C = A + B)
• Give your variables meaningful names (e.g. force1, F1, moment1, fAB for a force going from
A to B)
3
Helpful Matlab commands
• add = +
• subtraction = -
• multiplication = +
• division = /
• cos(x) acos(x)
• sin(x) asin(x)
• tan(x) atan(x)
• cot(x) acot(x)
• csc(x) acsc(x)
• sec(x) asec(x)
• atan2(x,y)
Careful!!! Matlab defaults to radians, so if you want to use degrees you have 2 options: