Menu

Matlab Cheat Sheet

MATLAB Purpose
Nifty Command
clc Clear command window
clear Clear system memory
clear x Clear x from memory
Matrices and vector
x(:) All elements of x
x(j:end) jth to end element of x
x(2:5) 2ndto 5th elements of x
Standart Matrix and vector operation
x=[1, 2, 3] 1x3 (row) vector defined
x=[1; 2; 3] 3x1 (column) vector defined
x=[1, 2; 3, 4] 2x2 matrix
x(2)=4 change index value nr 2
x.*y Element by element multiplication
x./y Element by elemnent division
A.^n normal/Matrix power of A
A' Transpose of A
inv(a) Inverse matrix
size(x) Rows and columns of matrix
eye(n) Identity matrix
sort(a) sorts vector from smallest to largest
eig(a) Eigenvalues and eigenvectors
angle(x) Get the argument value of complex number x, in radiant
abs(x) Get the absolute value of complex number x
Matrix operation and function
x(x>0)=0 change elements >5 to 0
Misc
x = linspace(0,50,6) Create an array from 0 to 50 with distributed stepsize divided by 6
x = 0 10 20 30 40 50
x = [ 0, 10, 20, 30, 40, 50 ]
q = [0:4:20] Create an array of from 0 to 20 with stepsize of 4
q = 0 4 8 12 16 20
q = [ 0, 4, 8, 12, 16, 20 ]
Constant
pi Produce the constant value of pi
exp(x) Produce exponent to the power of the number x
Graph Plotting
plot(x,y) Plot graph of y against x
title('Graph of y = x') Create a title on the top of the graph, "Graph of y = x"
xlabel('0 < x < 6') Create a label for the bottom x-axis, "0 < x < 6"
ylabel('y = x') Create a label for the left side y-axis, "y = x"
legend('y=x') Create a legend on the top right corner
grid on Switch on big grid on the generated graph
grid minor Add small grid line on the generated graph