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

MATLAB Cheat Sheet

This document provides a cheat sheet for MATLAB (MATrix LABoratory), a programming language for technical computing. It includes basic commands for clearing variables and plots, manipulating variables and matrices, performing arithmetic and functions, constructing matrices and vectors, and performing operations on matrices and vectors. It also includes commands for discretisation, cell manipulation, and entries/rounding of matrices and vectors. The cheat sheet is intended to provide an overview of essential MATLAB commands and capabilities.

Uploaded by

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

MATLAB Cheat Sheet

This document provides a cheat sheet for MATLAB (MATrix LABoratory), a programming language for technical computing. It includes basic commands for clearing variables and plots, manipulating variables and matrices, performing arithmetic and functions, constructing matrices and vectors, and performing operations on matrices and vectors. It also includes commands for discretisation, cell manipulation, and entries/rounding of matrices and vectors. The cheat sheet is intended to provide an overview of essential MATLAB commands and capabilities.

Uploaded by

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

THE CHEAT SHEET

SCIENCE
PROGRAMMING
ACADEMY WITH MATLAB
MATLAB (MATrix LABoratory) is a high-performance language for technical computing.
It integrates computation, visualization, and programming in an easy-to-use environment
where problems and solutions are expressed in familiar mathematical notation.

Small variables like x and y will be either row or column vectors and A will always be a matrix.

DISCRETISATION MANIPULATION OF VARIABLES


clc Clear command window a = 500 Define variable a to be 500
clear (all) Clear all variables x = [3, 1, 4] Set x to be the row vector [3, 1, 4]
close all Close all plots x = [3; 1; 4] Set x to be the column vector [3, 1, 4]T
clf Clear all plots A = [3, 1, 4, 1;
doc command Extensive help page for command 5, 9, 2, 6; Set A to be a 3 × 4 matrix
help command Quick help page for command 5, 3, 5, 8]
x(2) = 7 Change x from [3, 1, 4] to [3, 7, 4]
%This is a comment Indicates a comment
A(2,1) = 0 Change A(2,1) from 5 to 0
a = 5; Semicolon suppresses output
whos Lists all variables defined
disp('text') Print text BASIC ARITHMETIC & FUNCTIONS
save 'file.mat' save 'file.mat' 1*2, 3+4, 5-6, 7/8 Multiply, add, subtract and divide
load 'file.mat' Load variables from file.mat 28
^
Compute 28
diary on Record input/output to file diary sqrt(16) Compute √16
log(5) Compute ln(5)
ENTRIES OF MATRICES & VECTORS log10(100) Compute log10(100)
abs(-10) Compute | − 10|
abs(x) The absolute value of x
sin(2*pi/6) Compute sin(2π/6)
eps Floating point accuracy
ceil(3.8) Outputs 4.0
1e6 106
floor(3.8) Outputs 3.0
sum(x) Sums elements in x
round Rounds to the nearest integer
CELL MANIPULATION
Rounds to nearest integer greater than or
ceil equal to that element
x = cell(a, b) a x b cell array
fix Rounds to the nearest integer toward zero x{n,m} Access cell element n,m
floor Rounds to the nearest integer less than or cell2mat(x) Transforms cells to matrix
equal to that element

OPERATIONS ON MATRICES & VECTORS


CONSTRUCT MATRICES & VECTORS x+5 Add 5 to every element of x

zeros(5, 5) Create a 5 × 5 matrix of zeros (Pre-Allocation) x+y Elementwise addition of two vectors x and y

ones(6, 7) Create a 6 × 7 matrix of ones 10 * x Multiply every element of x by 10

eye(3) Create a 3 × 3 identity matrix A*y Product of a matrix and vector

eye(9, 10) Make a 9 × 10 identity matrix A*B Product of two matrices


Element-wise product of two matrices
linspace Generates N points between X and Y A .* B (Important if matrices are not quadratic)
(X, Y, N)
A^4 Square matrix A to the fourth power
logspace Creates a vector with N1 elements
(X1, Y1, N1) where the log of the spacing is evenly A .^ 4 Every element of A to the fourth power
increasing between X1 and Y1 cos(A) Compute the cosine of every element of A
1:99 Row vector of 1, 2, . . . , 88, 99 Compute the absolute values of every
abs(A)
element of A
A' Transpose of A
det(A) Compute the determinant of A
size(A) Get the size of A

This summary sheet is part of a course offered at the Science


The Science Academy Academy covering various science & engineering topics.
courses.jousefmurad.com For more information, please visit courses.jousefmurad.com

You might also like