0% found this document useful (0 votes)
2 views

DiscW1-MatlabCheatsheet

This MATLAB cheatsheet provides an overview of the interface and basic functionalities, including how to perform calculations in the Command Window and store results in the Workspace. It emphasizes the importance of creating meaningful variable names and offers guidelines for vector operations. Additionally, it lists helpful commands and notes the default use of radians in trigonometric functions, with options for degree calculations.

Uploaded by

da22024nish
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

DiscW1-MatlabCheatsheet

This MATLAB cheatsheet provides an overview of the interface and basic functionalities, including how to perform calculations in the Command Window and store results in the Workspace. It emphasizes the importance of creating meaningful variable names and offers guidelines for vector operations. Additionally, it lists helpful commands and notes the default use of radians in trigonometric functions, with options for degree calculations.

Uploaded by

da22024nish
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

MATLAB CHEATSHEET

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.

Now we can assign a variable to the answer:

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

• Create your vectors as variables (e.g. A = [1 2 3]; B = [3 4 5])

• Perform secondary calculations using these variables and save this as another variable (e.g.
C = A + B)

• DO NOT round intermediate calculations

• 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 = /

• det(D) : determinant of a square matrix

• dot(A,B): dot product of two vectors

• cross(A,B): cross product of two vectors

• norm(A): Magnitude of a vector

• 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:

• Cosd = cosine(in degrees)


OR
To convert from radians to degrees

• rad2deg (deg2rad also exists)

• Do the math itself

• pi is predefined in Matlab as ?pi?

You might also like