You are on page 1of 16

BITS Pilani

Pilani | Dubai | Goa | Hyderabad

Introduction to MATLAB
Ag e n da

1. What is MATLAB?
2. MATLAB Desktop
3. Matrices and Arrays
4. Operators (Arithmetic, relational, logical )
5. Flow Control
6. Using of M-File
7. Importing data
W h a t i s MAT L AB ?

o The name MATLAB stands for MATrix LABoratory.


o Designed by Cleve Moler
o Developer Math works
o Website mathworks.com/products/matlab Cleve Moler
o MATLAB is a high-performance language for technical computing. It integrates
computation, visualization, and programming environment.
o Furthermore, it has sophisticated data structures, contains built-in editing and
debugging tools, and supports object-oriented programming.
o These factors make MATLAB an excellent tool for teaching and research.
W h a t i s MAT L AB
Advantages
1. Ease of Use
2. Platform Independence
3. Predefined Functions
4. Device-Independent Plotting
5. Graphical User Interface
6. MATLAB Compiler

Disadvantages
7. Computational time
8. Cost
MAT L A B D e sk t o p
o Command Window
o Command History Window
o Current Directory Browser
o Workspace Browser
o Array Editor
o Editor/Debugger
o Figure Windows
o Help Browser
o M-Lint Code Check Report
Co m m a n d Win d ow
• The right-hand side of the default MATLAB desktop contains the Command
Window. A user can enter interactive commands at the command prompt (») in
the Command Window, and they will be executed on the spot.
Co m m a n d H is t or y Wi nd o w
The Command History Window displays a list of the commands that a user has entered
in the Command Window. The list of previous commands can extend back to previous
executions of the program. Commands remain in the list until they are deleted. To re execute
any command, simply double-click it with the left mouse.
Cu rr e nt Di re c t or y Br o ws e r
An Edit Window is used to create new M-files, or to modify existing ones. An
Edit Window is created automatically when you create a new M-file or open an
existing one. To search for, view, open, and make changes to MATLAB related
directories and files, use the MATLAB Current Directory browser. Alternatively, you
can use the functions dir, cd, and delete. Use the Visual Directory and Directory
Reports to help you manage M-files.
Wo r k s pa c e B r o ws e r
The MATLAB workspace consists of the set of variables (named arrays) built up
during a MATLAB session and stored in memory. To view the workspace and
information about each variable, use the Workspace browser.
Command Outcome
clear Clears the workspace, all variables are removed from the memory
clear x y z Clears only variables x, y, and z
clear all Clears all variables and functions from workspace
who Lists variables currently in the workspace
whos Lists variables currently in the workspace with their sizes together with information
about their bytes and class
Ar ra y E d i to r
Double-click a variable in the Workspace browser, or use openvar variable
name, to see it in the Array Editor. Use the Array Editor to view and edit a visual
representation of variables in the workspace.
E d i to r/ De bu g g e r

Use the Editor/Debugger to create and debug M-files, which are programs you
write to run MATLAB functions. The Editor/Debugger provides a graphical user
interface for text editing, as well as for M-file debugging.

Scripts and Functions

There are two kinds of M-files:


• Scripts, which do not accept input arguments or return output arguments. They
operate on data in the workspace.
• Functions, which can accept input arguments and return output arguments.
Internal variables are local to the function. (1)
F i gu r e Win d o ws

A Figure Window is used to display MATLAB graphics. A figure can be a two


or three-dimensional plot of data, an image, or a graphical user interface (GUI).

MATLAB Graphics

 Line plot
 Bar graph
 Surface plot
 Contour plot (2)
L i ne s ty l e

Line style, marker symbol, and color, specified as a string. The elements of the
string can appear in any order, and you can omit one or more options from the
string specifier. If you omit the line style and specify the marker character, then
the plot shows only the marker and no line.
Example: '--or' is a red dashed line with circle markers (3)

Specifier Line Style


- Solid line (default)
-- Dashed line
: Dotted line
-. Dash-dot line
Ma r ke r s y m b o l an d
Specifier Marker
o Circle
+ Plus sign
* Asterisk
. Point
x Cross
s Square
d Diamond
^ Upward-pointing triangle
v Downward-pointing triangle
>  Right-pointing triangle
<  Left-pointing triangle
p Pentagram
h Hexagram
c o l or

Specifier Color
y yellow
m magenta
c cyan
r red
g green
b blue
w white
k black
THANK YOU

You might also like