You are on page 1of 20

By Tejas M.

Kesarkar,
M. Tech. TFE,
tejaskesarkar.xlr8@gmail.com
+917208548978
MATLAB Layout
Command window (Enter commands directly, view output, give
inputs)
Workspace (Holds all the existing variables created by you while
running a program)
Initializing variables
v_name = XY will assign memory for a variable named
Variable_name and the value of XY will be stored at that location
d = zeros()
zeros function
Command window commands
clc : clears command window

clear v : frees the memory occupied by the variable v

clear all : frees the memory occupied by all variables

Ctrl + C : Terminate program while it is being executed


Math

operations
+ : addition
(+,-,/,*)
- : subtraction
/ : division
* : multiplication
Math operations (^,exp,log,log10)
^ : power
exp : exponetial
log : natural logarithm
log10 : logarithm to the base 10
Trignometric functions
sin(x) : sine asin(x) : sine inverse
cos(x) : cosine acos(x) : cosine inverse
tan(x) : tangent atan(x) : tangent inverse
csc(x) : cosecant acsc(x) : cosecant inverse
sec(x) : secant asec(x) : secant inverse
cot(x) : cotangent acot(x) : cotangent inverse
Hyberbolic functions
asinh(x) : hyperbolic sine inverse
sinh(x) : hyperbolic sine
acosh(x) : hyperbolic cosine inverse
cosh(x) : hyperbolic cosine
atanh(x) : hyperbolic tangent inverse
tanh(x) : hyperbolic tangent
acsch(x) : hyperbolic cosecant inverse
csch(x) : hyperbolic cosecant
asech(x) : hyperbolic secant inverse
sech(x) : hyperbolic secant
acoth(x) : hyperbolic cotangent
coth(x) : hyperbolic cotangent
inverse
Matrix algebra
det() : determinant of a square matrix
inv() : inverse of a non-singular square matrix
Matrix algebra
Accessing elements of an array, X(i,j) : first index will
denote the row number, second index will denote the
column number
Matrix algebra
Add, subtract, multiply matrices as simple variables
Creating programs using Editor
format for saving of files ____.m
Run programs using Run button
Anything written on a line after % will not be executed
disp() : Used for printing messages and values of variables
Creating programs using Editor
input() : used to assign values of variables by user. For string type of
inputs, enter string within single inverted commas
fprintf(string,variable_names,) : Used to print strings
Use \n for going to next line
Use %d for integer type and %f for floating point type, %s for
string type variables
remainder function
rem(x,y) : returns the remainder after division of x by
y
Conditional statements (different
types of conditions)
(a==b) : a is equal to b
(a~=b) : a is not equal to b
(a<b) : a is less than b
(a>b) : a is greater than b
(a<=b) : a is less than or equal to b
(a>=b) : a is greater than or equal to b
Arguments need not be single variables. They can be
expressions. E.g. (a<(b*c)) will mean a is less than the
product of b and c
Conditional statements (if-elseif-
else-end)
if(condition 1)
.statements
end
if(condition 1)
.statements.
else
..statements.
end
if(condition 1)
.statements
elseif(condition 1)
statements
end
Conditional statements (switch-
case-otherwise-end)
switch expression
case value_1
.statements.
case value_2
.statements.
end

switch expression
case value_1
.statements.
case value_2
.statements.
otherwise
.statements.
end
Using loops (for)
for i = start_value : step_value : end_value
statements to be repeated..
end
Note : Default step value is 1
Using

loops
while(condition)
(while)
..statements to be repeated..
end
Loop will be continuously executed until condition is proven to be false

You might also like