You are on page 1of 15

Elementary Computer

Programming
Chapter No. 2

Introduction to MATLAB
What is MATLAB?

• MATLAB stands for Matrix Laboratory.

• MATLAB is a tool for doing numerical computations


with matrices and vectors. It is very powerful and
easy to use. It integrates computation, graphics and
programming in the same environment.
• MATLAB is basically a high level language which has
many specialized toolboxes for making things easier
for us.
What is MATLAB?
Basic MATLAB Interface
To Get Help

If you want to see help, you can


.type help at the command window
? Or click
Variables
• No need for types. i.e.,
;int a
;double b
;float c

• All variables are created with double precision unless


specified and they are matrices.
:Example
;x=5>>
;x1=2>>

• After these statements, the variables are 1x1


matrices with double precision
Variables

• A data item that may take on more than one value


during the runtime of a program.
• Variable names can contain up to 63 characters
• Variable names must start with a letter followed by
letters, digits, and underscores.
• Variable names are case sensitive
Simple Calculations
Some Special Variables

• ans Default variable name for results


• pi Value of π
• inf Infinity
• NaN Not a number e.g. 0/0
Creating M-File

• What is M-File?
• An m-file is also called script file.
• It is a simple text file where you can
place MATLAB commands.
• When the file is run, MATLAB reads the
commands and executes sequentially.
• All m-file names must end with the extension
'.m' (e.g. test.m).
Creating M-File

To create an m-file,
1) type edit at the command
window, or
2) Press this button.
Creating M-File

The previous command will


.display the editor window
The editor creates an m-file
that can be used to write
.your MATLAB programs
Comments

A lines starting with % --- is a comments


Activity

• How we can assign the value 5 to the variable a


by using MATLAB?
1. int a=5;
2. var a=5;
3. a=5;
• What is the purpose of command window?
__________________
• Comments start with ________ .

You might also like