Cheat Sheet Matlab



  • MATLAB/Octave Python Description; sqrt(a) math.sqrt(a) Square root: log(a) math.log(a) Logarithm, base $e$ (natural) log10(a) math.log10(a) Logarithm, base 10.
  • Today's Pick comes to us from us. (Sounds circular, but power-user us apparently doesn't like capitals-or three-letter names!). In rex: a pedestrian regular expression operator synopsis generator, us has provided a very handy cheat sheet, of sorts, for creating Regular Expressions. For those of you who haven't yet delved the mysteries of.

fprintf

%4.2f in the formatSpec input specifies that the first value in each line of output is a floati­ng-­point number with a field width of four digits, including two digits after the decimal point. %8.3f in the formatSpec input specifies that the second value in each line of output is a floati­ng-­point number with a field width of eight digits, including three digits after the decimal point. n is a control character that starts a new line.

Line Properties

All cheat sheets, round-ups, quick reference cards, quick reference guides and quick reference sheets in one page. A Matlab Cheat-sheet (MIT 18.06, Fall 2007.

Color:
red = r
green = g

Matlab Cheat Sheet For Beginners

blue = b
cyan = c
magenta = m
yellow = y
black = k
Cheat Sheet Matlabwhite = w
none
LineStyle:
solid line = -
dashed line = --
dotted line = :
dash dotted line = -.
no line = none
SheetMarker:
circle = o
plus sign = +
asterisk = *
point = .
cross = x
square = square or s
diamond = diamond or d
none = noneCheat
Marker­Edg­eColor & Marker­Fac­eColor:
same as color
Marker­Indices

max

mean

plot examples

plot examples

sum

fprintf

%d in the formatSpec input prints each value in the vector, round(a), as a signed integer.

building arrays­/loops

max loop

  • MATLAB–Python–Julia cheatsheet

Dependencies and Setup¶

In the Python code we assume that you have already run importnumpyasnp

In the Julia, we assume you are using v1.0.2 or later with Compat v1.3.0 or later and have run usingLinearAlgebra,Statistics,Compat

Creating Vectors¶

Operation

MATLAB

Python

Julia

Row vector: size (1, n)

Column vector: size (n, 1)

1d array: size (n, )

Not possible

or

Integers from j to n withstep size k

Linearly spaced vectorof k points

Regexp Matlab Cheat Sheet

Cheat Sheet Matlab

Creating Matrices¶

Operation

MATLAB

Python

Julia

Create a matrix

2 x 2 matrix of zeros

2 x 2 matrix of ones

2 x 2 identity matrix

Diagonal matrix

Uniform random numbers

Normal random numbers

Sparse Matrices

Tridiagonal Matrices

Manipulating Vectors and Matrices¶

Operation

MATLAB

Python

Julia

Transpose

Complex conjugate transpose(Adjoint)

Concatenate horizontally

or

or

Concatenate vertically

or

or

Reshape (to 5 rows, 2 columns)

Convert matrix to vector

Flip left/right

Flip up/down

Repeat matrix (3 times in therow dimension, 4 times in thecolumn dimension)

Preallocating/Similar

N/A similar type

Broadcast a function over acollection/matrix/vector

Functions broadcast directly

Functions broadcast directly

Accessing Vector/Matrix Elements¶

Operation

MATLAB

Python

Julia

Access one element

Access specific rows

Access specific columns

Remove a row

Diagonals of matrix

Get dimensions of matrix

Mathematical Operations¶

Operation

MATLAB

Python

Julia

Dot product

Matrix multiplication

Inplace matrix multiplication

Not possible

Element-wise multiplication

Matrix to a power

Matrix to a power, elementwise

Inverse

or

or

Determinant

Eigenvalues and eigenvectors

Euclidean norm

Solve linear system(Ax=b) (when (A)is square)

Solve least squares problem(Ax=b) (when (A)is rectangular)

Sum / max / min¶

Operation

MATLAB

Python

Julia

Sum / max / min ofeach column

Sum / max / min of each row

Sum / max / min ofentire matrix

Cumulative sum / max / minby row

Cumulative sum / max / minby column

Programming¶

Matlab Quick Reference Sheet

Operation

MATLAB

Python

Julia

Comment one line

Comment block

For loop

While loop

If

If / else

Print text and variable

Function: anonymous

Function

Tuples

Can use cells but watch performance

Named Tuples/Anonymous Structures

Closures

Inplace Modification

No consistent or simple syntaxto achieve this