You are on page 1of 10

1

Matlab Overview
MATLAB is used in every facet of computational mathematics. Following are some commonly used
mathematical calculations where it is used most commonly −

● Dealing with Matrices and Arrays


● 2-D and 3-D Plotting and graphics
● Linear Algebra and equations
● Statistics
● Calculus and Differential Equations

MATLAB is widely used as a computational tool in science and engineering encompassing the fields of physics,
chemistry, math and all engineering streams. It is used in a range of applications including −

● Control Systems
● Test and Measurement
● Computational Finance

2
Matlab Interface

3
Basic Syntax
Basic arithmetic operations and variables
● ‘+’, ’-’, ’*’, ‘/’ can be used in matlab to perform basic operations.
for instance: input 5+5
ans=10
● variables can be declared to store data and can be retrieved later
from workspace.
example: ans,m,y
● exponentials , trigonometry functions can also be used.
3^2 ( ans=9 )
sin(pi/2) ( ans=1 )

4
● Semicolon (;) indicates end of statement. However, if you want to suppress
and hide the MATLAB output for an expression, add a semicolon after the
expression.
for example : x=3; y=x+5
input y
output 8

● The percent symbol (%) is used for indicating a comment line. For example,

x= 10 % x assigns the value of 10

● The save command is used for saving all the variables in the workspace, as a file
with .mat extension, in the current directory.
save myfile

5
6
Variables
You can assign variables in a simple way. For example,
x=3 %x assigns the value of 3
x=sqrt(16)
You can have multiple assignments on the same line.
a=2; b=7; c=a+b

Please note that

● Once a variable is entered into the system, you can refer to it later.
● Variables must have values before they are used.
● When an expression returns a result that is not assigned to any variable, the system
assigns it to a variable named ans, which can be used later.

7
int8 8-bit signed integer

int16 16-bit signed integer

structure C-like structures, each structure having named fields capable of storing

an array of a different dimension and data type

Char Convert to character array (string)

int2str Convert integer data to string

num2str Convert number to string

ischar Determine whether item is character array

8
Relational Operators

9
Conditional Statements

10

You might also like